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 !




How to Download Picture Forcefully from GridView/DataList


Posted Date: 01 Jul 2008    Resource Type: Code Snippets    Category: C# Syntax
Author: Rumpa MMember Level: Gold    
Rating: Points: 7



protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "dwn")
{
string picpath = Convert.ToString(e.CommandArgument);
int len = picpath.Length;
picname = picpath.Substring(8);
DownloadFile(picname, true);
}
}

public void DownloadFile(string fname, bool ForceDownload)
{
string path = MapPath("upload") + "\\" + fname;
string name = Path.GetFileName(path);
string ext = Path.GetExtension(path);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;

case ".txt":
type = "text/plain";
break;

case ".doc":
case ".rtf":
type = "Application/msword";
break;

case ".jpg":
type = "image/.jpg";
break;
case ".jpeg":
type = "image/.jpeg";
break;
case ".png":
type = "image/.png";
break;
case ".gif":
type = "image/.gif";
break;
}
}

if (ForceDownload)
{
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
}
Response.ContentType = type;
Response.WriteFile(path);
Response.End();
}




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search 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: How to Upload Files Using FileUpload Tool in ASP.NET.
Previous Resource: Connect using TCP Client
Return to Discussion Resource Index
Post New Resource
Category: C# Syntax


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use