File uploader
-
Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help
-
Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help
-
Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help
You need to give more information of your code, then any one can look on it and tell you what is the problem. :)
Viral My Site
Save Our Tigers -
Hey guys, am using a file uploader for a user to select a file, But only the files in my working directory are allowed. If I select a file outside my working directory i get an error saying: the path of the file could not be found...I would to choose a file from different directories Does any know what i can do on this one? Please help
-
Yes, we need detail description of your problem including code then only we can help you in better manner. :)
Jinal Desai
Hey thanks guys for ya reps, well i wish i would xplain this better, Here is a piece of code: below 'files' is the name of my file uploader
HttpPostedFile myFile = files.PostedFile;// Get a reference to PostedFile object
string strFilename = Path.GetFileName(myFile.FileName);//path of a file
if (strFilename != "")//check if a user has selected a file
{
string[] lines = File.ReadAllLines(strFilename);//will read all lines from a file
//here a runtime error fires saying the file path was not found
}Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens. So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found). E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception, and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory.. Please help Thanks Mor
-
Hey thanks guys for ya reps, well i wish i would xplain this better, Here is a piece of code: below 'files' is the name of my file uploader
HttpPostedFile myFile = files.PostedFile;// Get a reference to PostedFile object
string strFilename = Path.GetFileName(myFile.FileName);//path of a file
if (strFilename != "")//check if a user has selected a file
{
string[] lines = File.ReadAllLines(strFilename);//will read all lines from a file
//here a runtime error fires saying the file path was not found
}Reason: As anyone one else knows, when you choose browse on a file uploader, you can only select a file if it is present in the dialog box that opens. So if I select a file in my working directory, it works ok but if i select a file 'Outside' my working directory then I receive the error above(file not found). E.g my working directory is: C:\MyProject\SMS Send\contacts.txt this works and if I choose: C:\Documents and Settings\Morgan\Desktop\testing.txt this will give a FileNotFound exception, and when i look at this exception it is pointing to:C:\MyProject\SMS Send\testing.txt which is my working directory. I don't quiet understand why it is searching for the file from my working directory.. Please help Thanks Mor
You need to user Server.MapPath() while retrieving the full path. e.g: string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file I guess this should work now.
When you fail to plan, you are planning to fail.
-
You need to user Server.MapPath() while retrieving the full path. e.g: string strFilename = Server.MapPath(Path.GetFileName(myFile.FileName));//path of a file I guess this should work now.
When you fail to plan, you are planning to fail.
Thanks for your reply man but hey this gives me the same error(FileNotFound Exception) I don't quiet know why... :doh: