C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




download file


Posted Date: 05 Jul 2008      Total Responses: 1

Posted By: sathya       Member Level: Gold     Points: 1





hai ,

i want download files:

i will display some records with photo in datalist;i want download hole files
so

how to download ant want help me

any url path or kinds

Regards
sathya





Responses

Author: Jaya Kumar    05 Jul 2008Member Level: GoldRating:     Points: 6

In Grid View.. U place a Link Button in the Templete Field and the code as below


protected void lnkDownload_Click(object sender, EventArgs e)
{
try
{
lblError.Visible = false;
LinkButton lnk = (LinkButton)sender;
string strFileName =lnk.CommandArgument.ToString();
if (strFileName == "")
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "clientScript", "alert('File Not Found')", true);
}
else
{
//Response.ContentType = "application/octet-stream"
Response.Clear();
Response.ClearContent();
Response.ContentType = "application/x-download";
Response.AddHeader("Content-Disposition", "attachment;filename=" + Path.GetFileName(strFileName));
Response.WriteFile(Server.MapPath(strFileName));
Response.End();
}
}
catch (Exception ex)
{
lblError.Visible = true;
lblError.Text = ex.Message;
}
}


and in the GridView Row Created event u write this code

if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lnk = (LinkButton)e.Row.FindControl("lnkDownload");
lnk.CommandArgument = Convert.ToString(GridView1.DataKeys[e.Row.RowIndex].Values["Doc_Path"]);
}



Post Reply
You must Sign In to post a response.
Next : Replication
Previous : To sujit kumar
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use