Copy Files to Remote Location using ASP.Net
The following code transfers files to target Location:
string path = @"\\10.100.50.51\Personal\Venu Pavuluri\Texta.xls";
//Source File resides on Server Directory
string source = Server.MapPath("Test.xls");
File.Copy(source, path);
Response.Write("Trnsfered Successfully!!");
Render Excel File to Browser:
protected void TranferXlsFile()
{
string filename = "Test.xls";
if (filename != "")
{
string path = Server.MapPath(filename);
FileInfo file = new FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
Response.Write("This file does not exist.");
}
}
string path = @"\\10.100.50.51\Personal\Venu Pavuluri\Texta.xls";
//Source File resides on Server Directory
string source = Server.MapPath("Test.xls");
File.Copy(source, path);
Response.Write("Trnsfered Successfully!!");
Render Excel File to Browser:
protected void TranferXlsFile()
{
string filename = "Test.xls";
if (filename != "")
{
string path = Server.MapPath(filename);
FileInfo file = new FileInfo(path);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
Response.Write("This file does not exist.");
}
}
Comments