把已知路径的本地文件(不通过浏览选择),上传到远程服务器

woyaodubo woyaodubo 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
本地电脑没问题,上传到远程服务器就不行, 实在找不到办法了啊。


public void UploadFile()
{
//本地电脑文件路径
FileStream stream = new FileStream(@"C:\Users\li\Desktop\tb.txt", FileMode.Open, FileAccess.Read);
int size = Convert.ToInt32(stream.Length);
Byte[] bytes = new Byte[size];
stream.Read(bytes, 0, size);
stream.Close();
FileStream fos = null;

//上传到远程服务器
string filePath = Server.MapPath("~/DataFile/");
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
string fileName = "111.txt";
fos = new FileStream(filePath + fileName, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fos.Write(bytes, 0, bytes.Length);
fos.Close();
}

...全文

相关推荐

评论 34
收藏 已收藏
分享
返回顶部
woyaodubo
C# 111,128 成员 642,537 内容