Click here to Skip to main content
15,896,013 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hello everyone,,

as according to my requirement. i want something . i am just trying t o save the pdf file in a folder through insert query. as well it's running well in local server but when i am trying to upload this application to server it's not working . as i am feeling that there must be something that i need to change in path . i am providing my local server path code from which i am inserting pdf file in my database or folder as well. please have a look.



C#
protected void btnsave_Click(object sender, EventArgs e)
    {
        if (flUpld.HasFile == false)
        {
            lblerror.Text = "select a file to upload";
        }
        else
        {
            try
            {
                string filename = flUpld.FileName;
                find =Request.ApplicationPath;
                flUpld.PostedFile.SaveAs(Server.MapPath(find+"/results/" + filename.Trim()));
                string path = find+"/results/" + filename.Trim();

                if (ChangeData.InsertResult(ddlcategory.SelectedValue.ToString(), ddlsubcategory.SelectedValue.ToString(),
                txttitle.Text, path))
                {
                    txttitle.Text = "";
                    lblerror.Text = "sucessfully submitted";
                }
                else
                {
                    lblerror.Text = "try again later ";
                }
            }
            catch (Exception ex)
            {
               // Response.Write(ex.ToString());
            }
        }
    }



so please tell me is there any need to change in path for server
Posted
Updated 14-Mar-13 19:49pm
v2
Comments
Shubham Choudhary 14-Mar-13 7:06am    
hi!!! amit
for this firstly i want to say when you make a link which is download or any image so make the url for it!!! like image in img folder so you have to do like this image/img.jpg ok if you make url so automatically doing work
Shubham Choudhary 14-Mar-13 7:08am    
if you make pdf's id so make pdf file custom name which you want to write it always help you to makeing url
amitkumar5734 14-Mar-13 7:14am    
may be you are not getting what i want... provide me code that i can use on click of link button.. if you are not getting any thing ask me..
ZurdoDev 14-Mar-13 7:36am    
An easy way to do it is to just Response.Redirect(pathOfPdfFile)
amitkumar5734 14-Mar-13 8:04am    
nyanb31 it's not as easy as you are talking ..read carefully what i want..

1 solution

Try this...
C#
string pdfPath = Server.MapPath("~/SomePDFFile.pdf");
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(pdfPath);
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
 
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