我无法使用代码创建文件夹 [英] I can't create folder with code

查看:69
本文介绍了我无法使用代码创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

aspx文件: -

string filepath =/ uploads /+ companyname +_+ location +/+ Socode +/ Deliverables /+ Filename;



ashx文件: -



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,deliverrablesid,userid,fullpath);



我试过的:



i无法使用此代码创建文件夹或目录。请帮助!

解决方案

< blockquote> Windows使用\字符作为路径分隔符。而不是使用字符串连接来构建路径,而是使用System.Io.Path.Combine()。



此外,出于安全原因,您运行ASP的默认帐户.NET应用程序(在您使用的应用程序池中找到)将无权写入文件或在您的应用程序运行的文件夹下创建目录,或者任何地方。



您必须为此应用程序创建一个用户帐户,并为其提供NTFS权限,以便在您将网站推送到的应用程序文件夹中写入文件并创建文件夹。


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!

解决方案

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.


这篇关于我无法使用代码创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆