Solved

ASPX: How to get full url from local computer

Posted on 2013-01-08
10
481 Views
Last Modified: 2013-01-09
Hello. I am creating simple upload control that allow user to choose documents to upload. Problem: Seems like the file upload control does not give me the full url.  string myUrl = FileUploadControl.X; does not gives me something like "name.doc" but I need C:\XX\XX\Documents\name.doc"

Obviously I am missing something, but how on Earth can I get full url of the local file.
0
Comment
Question by:tolppa
10 Comments
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 111 total points
ID: 38754620
Odd question.
The user must select the file to upload - so you already have the filename and path
0
 
LVL 14

Assisted Solution

by:KoenVosters
KoenVosters earned 56 total points
ID: 38754636
http://asp.net-tutorials.com/controls/file-upload-control/

The control should already have the full path
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 38754649
Why would the server need to know the path of a file on the client system?
0
 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 55 total points
ID: 38754723
#38754649: Unless you want to ensure that the user didn't manually change the path in the fileupload control. -- I feel so.
0
 
LVL 12

Accepted Solution

by:
Jared_S earned 56 total points
ID: 38754764
I think what you're looking for is Path.GetFileName(fileupload1.FileName)

Here is a snippet of code that I use for a file upload event that also uses a label to let the client know the result of the operation. Obviously, mine isn't c#, but it isn't a difficult conversion.

If (fileupload1.HasFile) Then
            Try
                Dim Filename As String = Path.GetFileName(fileupload1.FileName)
                fileupload1.SaveAs( <serverpath> + "\" + Filename)
                filelist.Clear()
                 statuslabel.Text = Filename + " successfully loaded."
            Catch ex As Exception
                statuslabel.ForeColor = Drawing.Color.Red
                statuslabel.Text = "The file could not be uploaded. " + ex.Message
            End Try
        Else
            statuslabel.ForeColor = Drawing.Color.Red
            statuslabel.Text = "You have not specified a file."
        End If
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 18

Assisted Solution

by:Rajar Ahmed
Rajar Ahmed earned 56 total points
ID: 38755266
You cannot get complete directory path of client machine in any browser except internet explorer .

Here's the sample .
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="getDirectoryIE.aspx.vb" Inherits="getDirectoryIE" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title>Works Only On IE</title>
    <script type="text/javascript">
        function getimagefile() {
            var path = document.getElementById("imagepath").value
            document.getElementById("hdnPath").value = path;

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    Get Full path [IE ALONE YOU CAN ACHIEVE] <br />
    <input type="hidden" runat="server" id="hdnPath" />
    
        <asp:FileUpload ID="imagepath" runat="server" />
        <asp:Button ID="Button1" runat="server" Text="getPath" OnClientClick="getimagefile()" />
    
    </div>
    </form>
</body>
</html>

Open in new window

Partial Class getDirectoryIE
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Response.Write("Path is" & hdnPath.Value)
    End Sub
End Class

Open in new window


Meeran03
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 38755523
@informaniac

Why would that matter? It's the client's machine, and they haven't submitted the request yet; they can do whatever they want. Once the request has been sent to the server, the client cannot change what was sent.
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 111 total points
ID: 38755699
@kaufmed.  The asker is writing an upload control - isn't that taking a local file and putting to the web ?
0
 
LVL 75

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
ID: 38756114
@AndyAinscow

isn't that taking a local file and putting to the web ?
OK. But the whole design of the web (barring stuff like Flash--considering that's a plugin anyway) is that client and server are disconnected. Server does not have access to the client's machine, and browsers don't offer such access to web pages as a security measure. Unless he is writing an upload plugin, I don't see how he can enforce the full path being sent. As was already mentioned above ( http:#a38755266 ), IE is the only browser that supported such behavior.

As I mentioned, once the file is on the server, the local path of the file on the client's machine should be irrelevant.
0
 
LVL 1

Author Closing Comment

by:tolppa
ID: 38761901
Thanks. I am programming against sharepoint API which asked me to provide URL. Still, I actually did not need to provide URL but byte[] array. Apparently url works only when using files that exist in server. Solution was:

//FileUploadControl things
byte[] filethings= new byte[attach.ContentLength - 1]; 
SPFile spfile = myLibrary.Files.Add(fileinfo.Name, filethings, metadata_spthing, replaceFilesBoolean);

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now