Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
aspx file:-
string filepath = "/uploads/" + companyname + "_" + location + "/" + Socode + "/Deliverables/" + Filename;

ashx file:-

string filename = strfilename[0] + "_" + string.Format("{0:ddMMyyHHmmssfff}", DateTime.Now) + "." + FileExtension;
string fullpath = filepath +"/" +filename;
if (!System.IO.Directory.Exists(context.Server.MapPath("~" + fullpath)))
{
System.IO.Directory.CreateDirectory(context.Server.MapPath("~" + fullpath));
}
int i = objCF.InsertIntoAddSoDeliverablesDoc(uploads, deliverablesid,userid,fullpath);

What I have tried:

i am unable to create folder or directory with this code.please help!
Posted
Updated 24-Jun-16 2:40am
Comments
Richard MacCutchan 24-Jun-16 7:02am    
What is the actual string that you use in your call to CreateDirectory, and what status code do you receive?
Member 10549697 24-Jun-16 7:10am    
/uploads/Netscribes (I) Pvt Ltd_INDIA-Mumbai/SO0000/Deliverables/Default_240616154013830.txt


This is the fullpath i get in the database but path doesn't exist
Sergey Alexandrovich Kryukov 24-Jun-16 11:39am    
Are you sure that the path is a sub-directory of the root directory set up for your site?
—SA
Philippe Mori 24-Jun-16 18:51pm    
It seems that you are trying to create a directory with a filename. It does not make any sense. Use System.Io.Path function for concatenation and splitting. Use code block when asking a question. And write robust and maintainable code.

1 solution

Windows uses the "\" character as a path separator. Instead of using string concatenation to build paths, use System.Io.Path.Combine() instead.

Also, for security reasons, the default account your run your ASP.NET app under (found in the app pool you use) will NOT have permissions to write to files or create directories under the folder your app is running from, or anywhere for that matter.

You have to create a user account for this app and give it the NTFS permissions to write to files and create folders in the app folder you pushing your site to.
 
Share this answer
 
Comments
Member 10549697 27-Jun-16 7:22am    
Thank You Sir

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900