Click here to Skip to main content
15,885,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

I want to upload photo in my project..photo save to the server..and image retrive in image controls...and also want to save image url in textbox
Please help me ..

Presently i am working on Online admission procedure.


Thanks in advanced
Posted

1 solution

Try this if could help..
C#
 // This code download an image attachment from server...
 protected void lnkAttachment_Click(object sender, EventArgs e)
        {

            LinkButton lnkAttachment = (LinkButton)sender;
            GridViewRow row = (GridViewRow)lnkAttachment.NamingContainer;
            var fileName = ((LinkButton)row.FindControl("lnkAttachment")).Text;
            string sourcePath = Server.MapPath("~/Attachment/Contract/");
            string sourceFle = (Server.MapPath("~/Attachment/Contract/" + fileName.ToString()));
            string targetPath = this.txtTargetDir.Text;
            string targetFle = targetPath + "\\" + fileName;
            string result = string.Empty;
            this.txtAttachment.Value = string.Empty;
            if (!Directory.Exists(targetPath))
            {
               var ok = System.IO.Directory.CreateDirectory(targetPath);
            }
            if (!File.Exists(sourceFle ))
            {
                Tools.MessageBox.Show(this.Page, "Could not foud\\n" + sourceFle);
                string uploadedFile = sourceFle;
                string resultMes = cCmd.DeleteUploadFileName(uploadedFile);
                List<contract_attachmnt> lst = new List<contract_attachmnt>();
                lst = cCmd.GetAttachment(this.hfContracNo.Value);
                BindAttachment(lst);
                return;
            }
            try
            {
                Response.ContentType = "application/ms-excel";
                var attachmentFle = "attachment; filename=" + fileName;
                Response.AppendHeader("Content-Disposition",attachmentFle);
                var xx = Path.GetTempPath();
                Response.TransmitFile(sourceFle);
                Response.End();
            }
            catch (Exception)
            {
                result = "Error in downloading file.";
            }
            Tools.MessageBox.Show(this.Page, result);
        }
</contract_attachmnt></contract_attachmnt>


Regards,
 
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