I am using the FileUploader control in my web application. I'd like to upload the file in a specified folder. As the specific folder does not exist yet, I have to create the path it in my codes.
Could not find part of the path.
mscorlib.dll but was not handled in user code
Additional information: Could not find a part of the path
'C:\Users\seldarine\Desktop\PROJ\ED_Project\SFiles\Submissions\blueteam\Source.zip
I believe there is a problem with my filePath. This is a portion of my codes:
//teamName is a string passed from a session object upon login
string filePath = "SFiles/Submissions/" + teamName+ "/";
//If directory does not exist
if (!Directory.Exists(filePath))
{ // if it doesn't exist, create
System.IO.Directory.CreateDirectory(filePath);
}
f_sourceCode.SaveAs(Server.MapPath(filePath + src));
f_poster.SaveAs(Server.MapPath(filePath + bb));
Try :
//teamName is a string passed from a session object upon login
string filePath = "SFiles/Submissions/" + teamName+ "/";
string severFilePath = Server.MapPath(filePath);
// The check here is not necessary as pointed out by @Necronomicron in a comment below
//if (!Directory.Exists(severFilePath))
//{ // if it doesn't exist, create
System.IO.Directory.CreateDirectory(severFilePath);
//}
f_sourceCode.SaveAs(severFilePath + src));
f_poster.SaveAs(severFilePath + bb));
You need to check and create directory based on Server.MapPath(filePath);
, not filePath
(I assume that your src
and bb
are filenames without any sub directory paths).
It's better to use Path.Combine instead of concatenating strings:
f_sourceCode.SaveAs(Path.Combine(severFilePath,src));
f_poster.SaveAs(Path.Combine(severFilePath,bb));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With