将文件保存在其他计算机(在同一域中)
本文关键字:保存 文件 存在 其他 计算机 | 更新日期: 2023-09-27 18:11:37
我有一些web应用程序在ASP。. NET和我想保存文件到同一域/网络的其他计算机。如果可能的话,我该怎么做呢?
如果你要上传一个流,可以这样保存文件到网络路径:
public void SaveFile(Stream fileStream, string filename)
{
try
{
using (var newFile = File.Create(@"''NetworkPath'" + filename))
{
fileStream.CopyTo(newFile);
fileStream.Close();
fileStream.Dispose;
}
}
catch (Exception ex)
{
//Log if something goes wrong
LogException(ex);
}
}
我建议使用File.Exists()
检查文件夹中是否存在同名的文件,您可以使用Directory.Exists()
检查目录是否存在
可以,只需像往常一样使用save,但要事先指定要保存到的机器的IP地址。
例如。在保存方法中,必须指定一个位置。在你的例子中,只需给它一个IP地址。
void SaveFile(HttpPostedFile file)
{
// Specify the path to save the uploaded file to.
string savePath = "''192.168.0.1''temp''uploads''";