Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am developing a website in ASP.net 3.5. I want to develop a way to upload a resume in *.doc format. How do I upload and download a MS Word document from a server and database with a delete and update operation?

Thanks.

Debapriya


[orig. title]
How to upload and download a word document in server and database with delete and update operation.
Posted
Updated 18-Mar-11 0:13am
v2

 
Share this answer
 
v3
Comments
Albin Abel 18-Mar-11 6:22am    
Did OP asked about mobile development?
Wild-Programmer 18-Mar-11 6:23am    
By mistake posted someone else answer in his. Correcting it.
lovercsharpasp 5-Jul-11 5:50am    
not important but thank you in this links its vgod i give 5 there something else i was think in it
lovercsharpasp 5-Jul-11 5:47am    
no but this is vg
try
{ // Read the file and convert it to Byte Array
string filePath = FileUpload1.PostedFile.FileName;
string filename = Path.GetFileName(filePath);
string ext = Path.GetExtension(filename);
string contenttype = String.Empty;
//Set the contenttype based on File Extension
switch (ext)
{
case ".doc":
contenttype = "application/vnd.ms-word";
break;
case ".docx":
contenttype = "application/vnd.ms-word";
break;
}
if (contenttype != String.Empty)
{ Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
//insert the file into database
string strQuery = "insert into careers(cv,extcv,namecv) values (@cv,@extcv,@namecv)";
SqlCommand cmd = new SqlCommand(strQuery);
// NAME OF THE CV
cmd.Parameters.Add("@namecv", SqlDbType.NVarChar).Value = filename;
//EXTENTION OF THE CV DOCUMENT
cmd.Parameters.Add("@extcv", SqlDbType.NVarChar).Value = contenttype;
//CV DATA BINARY
cmd.Parameters.Add("@cv", SqlDbType.Binary).Value = bytes;
//function bolean
InsertUpdateData(cmd);
//RESPONSE TO ANOTHER PAGE
Response.Redirect("done.aspx");
}
else
{ lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "File format not recognised. Upload Image/Word/PDF/Excel formats";
}

}

catch (Exception exr)
{Response.Write(exr.Message);
}


}
// THE FUUNCTION IN FOR INSERT THE FILE DB
private Boolean InsertUpdateData(SqlCommand cmd)
{
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["dballharam"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
//COMMAND TEXT IN BUTTOM CLICK
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
Response.Write(ex.Message);
return false;
}
finally
{
con.Close();
con.Dispose();
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900