我在ASP.NET中有一些Web应用程序,我想将文件保存到同一域/网络中的其他计算机。如果有可能我该怎么做?
答案 0 :(得分:1)
如果要上传流,可以按如下方式将文件保存到网络路径:
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()
检查目录是否存在
答案 1 :(得分:0)
是的,只需像往常一样使用保存,但事先指定要保存的机器的IP地址。
例如。在您的保存方法中,您必须指定一个位置。在你的情况下,只需给它一个IP地址。
void SaveFile(HttpPostedFile file)
{
// Specify the path to save the uploaded file to.
string savePath = "\\192.168.0.1\\temp\\uploads\\";