Solved

Capture the relevant path

Posted on 2013-12-17
12
30 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 74

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 74

Expert Comment

by:käµfm³d 👽
ID: 39725804
Have your user type it into a text box.
0
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to go to Web page 2 52
C# SQL BULK INSERT CLASS 5 36
cs.Designer Issue 2 20
Round up to 100% in .NET 10 46
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
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)

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now