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.");
}
}

Comments

Popular posts from this blog

Windows Azure Package Build Error: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

Resource ID : 1. The request limit for the database is 180 and has been reached.

Update Excel Sheet using C#, Where Excel not Installed on Server