• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 47
  • Last Modified:

Capture the relevant path

Hi,
when running the deployed project in the client machine, I try to catch the full path of the selected file, using these codes

            if (FileUploadControl.HasFile)
            {
                try
                {
                    ...
                    tb_fullname.Text = System.IO.Path.GetFullPath(FileUploadControl.PostedFile.FileName);
                    ...

Open in new window

but I checked that tb_fullname.Text is having the value like
c:\windows\system32\inetsrv\file1.png

not the relevant path in the client machine, in which I'm choosing the file to upload. How to adjust the above?
0
HuaMinChen
Asked:
HuaMinChen
  • 6
  • 3
  • 2
1 Solution
 
käµfm³d 👽Commented:
It is a security risk for the browser to divulge the location of a file on it's own disk. Only non-standards-compliant browsers (like early editions of IE) transmit this information.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Is there no way to retrieve that kind of information of the file?
0
 
käµfm³d 👽Commented:
Have your user type it into a text box.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
HuaMinChenBusiness AnalystAuthor Commented:
I do try to show the full path of the selected file, in a Textbox.
0
 
Minh Võ CôngCommented:
Do you try tb_fullname.Text = FileUploadControl.FileName;
FileUploadControl.FileName is client path
FileUploadControl.PostedFile.FileName is Server Path
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.filename%28v=vs.110%29.aspx
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Hi,
with this line
tb_flext.Text = System.IO.Path.GetExtension(FileUploadControl.FileName);
...

Open in new window

I then rerun the redeployed project, and have selected the file from

c:\shared

that is in the local machine

but I still get this in the Textbox
c:\windows\system32\inetsrv\t315.png
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Any help?
0
 
Minh Võ CôngCommented:
you can try use javascript to get client filename
read the topic
http://javadotnet.in/2012/10/get-file-name-using-javascript-asp-net-fileupload-control/

<script type="text/javascript">
function getFileName() {
var varfile = document.getElementById("FileUploadControl");
document.getElementById("filename").value = varfile.value;
}

<asp:FileUpload ID="FileUploadControl" runat="server" onchange="getFileName()" />
<td>
<input type="text" id="filename" />
</td>
0
 
HuaMinChenBusiness AnalystAuthor Commented:
Sorry, how to show the value of the path in the Textbox?
0
 
Minh Võ CôngCommented:
When you select the file onchage event on getFileName func, in getFileName update content of filename.
0
 
HuaMinChenBusiness AnalystAuthor Commented:
How?
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now