Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在其他计算机中保存文件(在同一域中)_C#_Asp.net - Fatal编程技术网

C# 在其他计算机中保存文件(在同一域中)

C# 在其他计算机中保存文件(在同一域中),c#,asp.net,C#,Asp.net,我在ASP.NET中有一些web应用程序,我想将文件保存到同一域/网络中的其他计算机。如果可能的话,我该怎么做?是的,只需按正常方式保存,但在指定要保存到的机器的IP地址之前 比如说。在保存方法中,必须指定一个位置。在您的情况下,只需给它一个IP地址 void SaveFile(HttpPostedFile file) { // Specify the path to save the uploaded file to. str

我在ASP.NET中有一些web应用程序,我想将文件保存到同一域/网络中的其他计算机。如果可能的话,我该怎么做?

是的,只需按正常方式保存,但在指定要保存到的机器的IP地址之前

比如说。在保存方法中,必须指定一个位置。在您的情况下,只需给它一个IP地址

void SaveFile(HttpPostedFile file)
      {            
        // Specify the path to save the uploaded file to.
        string savePath = "\\192.168.0.1\\temp\\uploads\\";

如果您正在上载流,则可以按如下方式将文件保存到网络路径:

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()
检查文件夹中是否存在同名文件,您可以使用UNC路径使用
directory.exists()

检查目录是否存在。我可以在C#桌面应用程序中使用它吗?