I have some web app in ASP.NET and I would like to save file to other computer in same domain/network. If it is possible how can I do this?
Asked
Active
Viewed 1,787 times
2 Answers
1
If you are uploading a stream, saving a file to a network path can be done like this:
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);
}
}
I would recommend checking if a file with the same name exists in the folder by using File.Exists()
and you can check the directory exists using Directory.Exists()

John
- 1,268
- 16
- 25
0
Yes, just use save as you normally would but prior specify the IP address of the machine you would like to save it to.
For example. In your save method you'll have to specify a location. In your case just give it an IP address.
void SaveFile(HttpPostedFile file)
{
// Specify the path to save the uploaded file to.
string savePath = "\\192.168.0.1\\temp\\uploads\\";

Jay
- 2,107
- 4
- 20
- 24