Solved

Capture the relevant path

Posted on 2013-12-17
12
39 Views
Last Modified: 2015-09-10
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
Comment
Question by:HuaMinChen
  • 6
  • 3
  • 2
12 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39725776
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39725784
Is there no way to retrieve that kind of information of the file?
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39725804
Have your user type it into a text box.
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 10

Author Comment

by:HuaMinChen
ID: 39725823
I do try to show the full path of the selected file, in a Textbox.
0
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39726873
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39734420
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39735285
Any help?
0
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 125 total points
ID: 39735535
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
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39735561
Sorry, how to show the value of the path in the Textbox?
0
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39735585
When you select the file onchage event on getFileName func, in getFileName update content of filename.
0
 
LVL 10

Author Comment

by:HuaMinChen
ID: 39735599
How?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

837 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