C# 在其他计算机中保存文件(在同一域中)
我在ASP.NET中有一些web应用程序,我想将文件保存到同一域/网络中的其他计算机。如果可能的话,我该怎么做?是的,只需按正常方式保存,但在指定要保存到的机器的IP地址之前 比如说。在保存方法中,必须指定一个位置。在您的情况下,只需给它一个IP地址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
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#桌面应用程序中使用它吗?