Reputation: 4283
Why is my file path nothing when I browse for a file using FileUpload? I don't want to upload a file, I just want to get the directory of a file (I'm using that file to update a SQL database with (xlsx file))
<asp:FileUpload ID="FileUpload" runat="server" Height="24px" Style="position: static" Width="255px" />
<asp:Button ID="Uploadbtn" runat="server" OnClick="Uploadbtn_Click" Style="position: static" Text="Upload" Width="82px" />
Code Behind (Test is "") on Uploadbtn_Click event
string test = FileUpload.FileName;
Upvotes: 1
Views: 4543
Reputation: 5636
For this question answer is we don’t have chance to get full path of uploaded file from fileupload control because of some security reasons browsers will return only file name instead of full file path from client machine.
If you want to get full path of uploaded file from fileupload control from client machine we need to save that file in our application folder from that we can get path of that file like as shown below
Code:
string filename = Path.GetFileName(fileUpload.PostedFile.FileName);
fileUpload.SaveAs(Server.MapPath("Files/"+filename));
string filepath = "Files/"+filename;
Hope you understand..
Upvotes: 0
Reputation: 12944
As you can read at MSDN (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.fileupload.filename.aspx), the filename will NEVER contain the directory of that file.
The software on the server is never allowed to take a peek inside the clients computer.
Upvotes: 1