Click here to Skip to main content
15,918,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone know please rectify following error:


this code working well in local but in server through this error what can i do for rectify this error....


Eror:



SQL
Record Not Inserted SuccessfullyCould not find a part of the path 'D:\Hosting\7375777\html\userside\clogo\indexrrr.jpg' is denied.



Coding:


protected void btnnadd_Click1(object sender, EventArgs e)
   {
       if (uploadlogo.HasFile == true)
       {
           try
           {
               //string fileName = Server.HtmlEncode(uploadcollogo.FileName);
               System.Drawing.Image image_file = System.Drawing.Image.FromStream(uploadlogo.PostedFile.InputStream);
               int image_height = image_file.Height;
               int image_width = image_file.Width;
               int max_height = 240;
               int max_width = 320;
               image_height = (image_height * max_width) / image_width;
               image_width = max_width;
               if (image_height > max_height)
               {
                   image_width = (image_width * image_height) / image_width;
                   image_width = max_width;
               }
               Bitmap bitmap_file = new Bitmap(image_file, image_width, image_height);
               System.IO.MemoryStream stream = new System.IO.MemoryStream();
               bitmap_file.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
               stream.Position = 0;
               byte[] image = new byte[stream.Length + 1];
               stream.Read(image, 0, image.Length);
               string fileName = Path.GetFileName(uploadlogo.FileName);
               string image1 = "../userside/clogo/" + fileName;
               string status = "Active";
               //SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["constring"].ToString());
               SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString);
               cn.Open();
               SqlCommand cmd = new SqlCommand();
               cmd.CommandText = "pcompinsert";
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.Parameters.AddWithValue("@cname", txtcompname.Text);
               cmd.Parameters.AddWithValue("@cmobile", txtcompmobile.Text);
               cmd.Parameters.AddWithValue("@clandline", txtcomplandline.Text);
               cmd.Parameters.AddWithValue("@cemail", txtcompemail.Text);
               cmd.Parameters.AddWithValue("@caltemail", txtalternateemail.Text);
               cmd.Parameters.AddWithValue("@cfaxno", txtcompfaxno.Text);
               cmd.Parameters.AddWithValue("@caddr", txtcaddr.Text);
               cmd.Parameters.AddWithValue("@ccategory", txtcategory.Text);
               cmd.Parameters.AddWithValue("@cwebsite", txtcompwebsite.Text);
               cmd.Parameters.AddWithValue("@ccity", txtcompcity.Text);
               cmd.Parameters.AddWithValue("@ccountry", ddlcountry.SelectedItem.Value);
               cmd.Parameters.AddWithValue("@cstate", ddlstate.SelectedItem.Text);
               cmd.Parameters.AddWithValue("@clandmark", txtcomplandmark.Text);
               cmd.Parameters.AddWithValue("@cstatus", status);
               SqlParameter UploadedImage = new SqlParameter("@clogo", SqlDbType.Image, image.Length);
               UploadedImage.Value = image;
               cmd.Parameters.Add(UploadedImage);
               cmd.Connection = cn;
               cmd.ExecuteNonQuery();
               uploadlogo.SaveAs(Server.MapPath(image1));
               cn.Close();
               clear();
               Page.ClientScript.RegisterStartupScript(this.GetType(), "Inserted", "<script>alert('Record Inserted Sucessfuly')</script>");

           }


           catch (Exception ex)
           {
               lblerrmsg.Text = "Record Not Inserted Successfully" + ex.Message;
           }

       }
   }
Posted
Updated 23-Feb-12 1:44am
v3
Comments
Bojjaiah 23-Feb-12 4:44am    
I think you have permissions problem once check out.

The error message is pretty clear: the path is bad.
You need to check the relative path you are adding:
C#
string image1 = "../userside/clogo/" + fileName;

By preference, make that an absolute path instead - otherwise it is relative to the current page, not the whole website. So if you have two pages using the same code, they need to be in the same directory to work.
 
Share this answer
 
Comments
M.Narmatha 23-Feb-12 4:20am    
can't understand...
OriginalGriff 23-Feb-12 5:57am    
Any path which starts ".." means the the path is relative to the current folder - in fact to the parent of the current folder.
If you specify a relative path, then you have to be sure where the page is actually located, because the location of teh current page will be the current folder.
If you use an absolute path, then you are specifying exactly where the file should be located.
If your page is in a folder "loginRequired" from your website root, then
"../Images/xx.jpg"
Expects Images to be in the website root.
In your page is in the root, then it expects Images to be ABOVE the root.
"/Images/xx.jpg" is an absolute path which would always look for Images in the root.
M.Narmatha 23-Feb-12 7:12am    
how can i give folder path.... i have to store image into userside-clogo
OriginalGriff 23-Feb-12 8:49am    
Userside? Do you mean Client side? On the Client PC rather than the server?
sathiyak 25-Feb-12 2:03am    
in server...
I think you are using Goddady Server :)
Its a permission problem,
please set the write permission to the "clogo" folder
 
Share this answer
 
Comments
M.Narmatha 23-Feb-12 4:56am    
how to set..i d't know

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