Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASPX: How to get full url from local computer

Posted on 2013-01-08
10
Medium Priority
?
490 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 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 444 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 224 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 664 total points
ID: 38754649
Why would the server need to know the path of a file on the client system?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 20

Assisted Solution

by:informaniac
informaniac earned 220 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 224 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 224 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 664 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 45

Assisted Solution

by:AndyAinscow
AndyAinscow earned 444 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 664 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 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