C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » C# Syntax »

Stored Files are Retrived using this code


Posted Date: 22 May 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Ashok KandasamyMember Level: Diamond    
Rating: 1 out of 5Points: 10



Hi,
This code is used to retrive the file which is already stored in the server using fileupload control.
[CODE}
protected void btnExcelTemplate_Click(object sender, EventArgs e)
{
// string xlsPath = Request.PhysicalApplicationPath;
try
{
string xlsPath = Request.PhysicalApplicationPath + @"\Template\Training";
string filePath = xlsPath + @"\TrainingHistory.xls";
if (File.Exists(filePath))
{
FileInfo fi = new FileInfo(filePath);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;

Response.AppendHeader("Content-Disposition", "attachment;filename = " + System.Web.HttpUtility.UrlEncode(System.Text.Encoding.UTF8.GetBytes("TrainingHistory.xls")));
Response.AppendHeader("Content-Length", fi.Length.ToString());

Response.ContentType = "application/ms-excel";
Response.WriteFile(filePath);
Response.Flush();
Response.End();
}
}
catch (Exception exp)
{
lblMessage.Text = exp.Message;
}

}




Responses

Author: Balamurali Balaji    22 May 2008Member Level: Diamond   Points : 2
Hi,

Your code opens excel to show the specified file. It does not show excel data on a web page.

How do we display excel data on the page?

Goodluck


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Programmatically Compile WebSite
Previous Resource: How to Subtract Dates
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use