Click here to Skip to main content
15,898,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 20:08pm
v2
Comments
Karthik Harve 15-Mar-13 2:09am    
[Edit] removed wrong pre tag.
Prasad Khandekar 15-Mar-13 2:15am    
Hello Amit,

May be folder named result does not exists on the sever and the ASP.NET user account does not have necessary permissions to create a folder and or save a file in it. Try logging the exception to a log file or event log. it will give you more insight in understanding why it's not happening on remote server.

Regards,
amitkumar5734 15-Mar-13 2:29am    
prasad : sir actually folder exists on server i have given all the permission to folder . folder name is same as i have given like result.

You need to create a service account for your application server as you may not have enough permission to save the file in the server. Then you should use asp.net impersonation with the service account to upload the file to that server. This is exactly how I upload the files in the server.
 
Share this answer
 
Comments
amitkumar5734 15-Mar-13 3:01am    
actually i have given all the permission to folder. and i have discussed to the technicians of that company from i have purchased web space or panel. they told me everything is ok from us. they also told me that we have also provided the all permissions ... but why is this happening . i am not able to solve. if just ask you. that the type of providing path name is that ok with server.. or not... or if any one can customize this code according to suitable for server...
that can be run over the server...
XML
If you know exactly where the file should be stored and if is a constant path, then you can save in the config file or DB. Then you can read the path and append the filename with it and finally save.

in config: <add key="UploadPath" value="\\fsvcsdev5536\App\Files"/>
in code:
string folderPath = ConfigurationManager.AppSettings["UploadPath"].ToString();
string fileDest = folderPath + "\\" +  fileName.trim();
this.flUpld.SaveAs(fileDest);
 
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