I’m trying to get the full path of a file using the file upload feature in asp.net. I’m working on a website project using C# in Visual Basic 2010. The reason I want the full path is because I’m actually trying to get information on the folder which contains the file, because the plan is to compare the contents of two folders using a third-party compare tool, UltraCompare, and then transfer the results of that comparison into our database.
Ideally, I’d like a feature that enables the user to browse for a folder rather than a file, but as far as I can tell from my googling, this is not possible in .net 4.0, which is the version I’m using.
I’m not sure if it’s even necessary to use the file upload control at all, as all I require is the filepath of the directory. However, I would like something that enables the user to search for a file using a GUI browser window as opposed to typing in the full file path.
I’m obviously a huge noob with C# .net and programming in general, so any advice or suggestions would be greatly appreciated. Here is some sample code I copy-and-pasted from somewhere else. The stuff in comments is just me trying out (unsuccessfully) different methods for getting the file path.
if (File1.HasFile)
{
try
{
//string filepath1 = Path.GetFullPath(File1.PostedFile.FileName);
string filepath1 = Path.GetFileName(File1.FileName);
File1.SaveAs(Server.MapPath("~/") + filepath1);
//StatusLabel.Text = "Upload status: File(s) uploaded!";
Response.Write("Upload status: File(s) uploaded! <br />");
Response.Write(filepath1);
}
catch (Exception ex)
{
StatusLabel.Text = "Upload status: The file(s) could not be uploaded. The following error occured: " + ex.Message;
//Response.Write("Upload status: The file(s) could not be uploaded. The following error occured: " + ex.Message + "<br />");
}
html does not give you anything other than the original file name. any additional information, such as folder path or properties, would be a breach of the client’s security and privacy. You’ll need to use something else, like an activex control or adobe flash to get the data you are after.