.net 上传文件选择服务器路径,.net c#在远程服务器中创建目录和文件

I am trying to create directories and upload files to the server, but it won't give me access to. This is my code:

if (FileUploadControl.HasFile)

{

string path = "~/MSImages/";

string mappath = Server.MapPath(path);

if (FileUploadControl.PostedFile.ContentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))

{

string extension = FileUploadControl.PostedFile.FileName;

extension = extension.Substring(extension.LastIndexOf('.'));

if (!Directory.Exists(mappath))

Directory.CreateDirectory(mappath);

string filename = imgext + Request.QueryString["id"];

FileUploadControl.SaveAs(mappath + filename + extension);

}

}

It works when done on my local computer, but not when on my host. How to fix this?

Solutions1

This is most likely a permission issue. Your IIS account user doesn't have the appropriate permissions to change the resource on the other machine.

You could change the IIS user to a low-permission domain user that is just granted access to that specific machine's share. That should fix your issue.

Talk1:

If I don't have access to the IIS settings, can I connect to the FTP somehow in C# and create directories/files?

Talk2:

If you have the appropriate permissions: yes.

Talk3:

I have access to the FTP server and I can add/remove any file I want in there.

Talk4:

And by the way, you don't need to change anything in IIS. You just have to grant the IIS user access to that share. If you can do that, you are there too.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值