Solved

ASPX: How to get full url from local computer

Posted on 2013-01-08
10
482 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
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 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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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