Solved

Capture the relevant path

Posted on 2013-12-17
12
41 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
[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
  • 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
Industry Leaders: 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!

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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)

752 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