Showing posts with label Upload/Download. Show all posts
Showing posts with label Upload/Download. Show all posts

Wednesday, October 8, 2008

How to download PDF on Button click using asp.net

// html part ...

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>Download Filestitle>

head>

<body>

<form id="form1" runat="server">

<div>

<asp:Button ID="Button_Download" runat="server" Text="Download" OnClick="Button_Download_Click" />

div>

form>

body>

html>


// code part ...

protected void Button_Download_Click(object sender, EventArgs e)

{

string str_FilePath = Server.MapPath(".") + @"\UploadedItems\Docs\CV.pdf";

System.IO.StreamReader sr = new System.IO.StreamReader(str_FilePath);

Response.BufferOutput = true;

Response.AppendHeader("content-disposition", "attachment; filename=v.pdf");

Response.ContentType = "application/pdf";

Response.TransmitFile(str_FilePath);

}


-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript

Friday, January 25, 2008

Uploading Images in ASP.Net 2.0

string DefaultImageName = System.IO.Path.GetExtension ( System.IO.Path.GetFileName( FileUpload_CompanyLogo.FileName));


string DefaultImagePath = Server.MapPath(".") + "/Agent_Logos/"+ Session["SellerID"] +"_Logo"+ DefaultImageName;

SaveAgentLogo(DefaultImagePath);



//Method to save the agent logo ...

private void SaveAgentLogo(string DefaultImagePath)

{

// Create and store the default image and its thumbnail.

FileUpload_CompanyLogo.PostedFile.SaveAs(DefaultImagePath);

string fileName = System.IO.Path.GetFileName(DefaultImagePath);

string strThumbnailPath = Server.MapPath(".") + @"/Agent_Logos/Thumbnails/" + fileName;

ThumbImage.C_Thumbnails(50, DefaultImagePath, strThumbnailPath);

}


-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript

Tuesday, January 22, 2008

Upload Videos in ASP.Net

protected void btnUpload_Click(object sender, EventArgs e)

{

string Venu = Request.QueryString["Venu"];

if (!( UVideo.PostedFile.ContentType == "video/x-ms-wmv" || UVideo.PostedFile.ContentType == "video/mpg" || UVideo.PostedFile.ContentType == "video/mpeg" || UVideo.PostedFile.ContentType == "video/divx" || UVideo.PostedFile.ContentType == "video/div" || UVideo.PostedFile.ContentType == "video/tix" || UVideo.PostedFile.ContentType == "video/mp4" || UVideo.PostedFile.ContentType == "video/qt" || UVideo.PostedFile.ContentType == "video/mov" || UVideo.PostedFile.ContentType == "video/avi" || UVideo.PostedFile.ContentType == "video/mp3" || UVideo.PostedFile.ContentType == "video/mpa" || UVideo.PostedFile.ContentType == "video/mpe" || UVideo.PostedFile.ContentType == "video/mp2" || UVideo.PostedFile.ContentType == "video/m1v" ))

{

pnlRight.Visible = false;

pnlWrong.Visible = true;

lblError.Text = "Video Extension Not Match";

return;

}

string file = System.IO.Path.GetFileName( System.IO.Path.GetExtension( UVideo.PostedFile.FileName ));

string loc = Server.MapPath("..")+ @"\"+ Venu + @"\Videos\" + ViewState["Id"].ToString() + file;

UVideo.PostedFile.SaveAs(loc);

SqlConnection sqlcon;

SqlCommand sqlcmd;

sqlcon = new SqlConnection ( System.Configuration.ConfigurationManager.AppSettings ["ConStr"] );

try

{

sqlcon.Open();

sqlcmd = new SqlCommand("updt_Video", sqlcon);

sqlcmd.CommandType = CommandType.StoredProcedure;

sqlcmd.Parameters.AddWithValue("@Vid", ViewState["Id"]);

sqlcmd.Parameters.AddWithValue("@VTitle", txtTitle.Text);

sqlcmd.Parameters.AddWithValue("@VPath", ViewState["Id"] + file);

sqlcmd.ExecuteNonQuery();

sqlcon.Close();

pnlRight.Visible = true;

pnlWrong.Visible = false;

lblRight.Text = "Video Uploaded Sucessfully";

}

catch (Exception ex)

{

sqlcon.Close();

Response.Write(ex.ToString());

}

finally

{

sqlcon.Close();

}

}



-
ShriKrishna Bhardwaj , With ASP.Net, SQL Server, Javascript