Solved

ASPX: How to get full url from local computer

Posted on 2013-01-08
10
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

726 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