Solved

ASPX: How to get full url from local computer

Posted on 2013-01-08
10
480 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
Comment Utility
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
Comment Utility
http://asp.net-tutorials.com/controls/file-upload-control/

The control should already have the full path
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
Comment Utility
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
Comment Utility
#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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 18

Assisted Solution

by:Rajar Ahmed
Rajar Ahmed earned 56 total points
Comment Utility
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 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
Comment Utility
@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
Comment Utility
@kaufmed.  The asker is writing an upload control - isn't that taking a local file and putting to the web ?
0
 
LVL 74

Assisted Solution

by:käµfm³d 👽
käµfm³d   👽 earned 166 total points
Comment Utility
@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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

7 Experts available now in Live!

Get 1:1 Help Now