Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm designing my web page i want store image location and then customer record i am doing photo studio management studio system image location not store...
protected void Button1_Click(object sender, EventArgs e)
        {
           
        }
        public string onflbload(FileUpload UploadedFile)
       {
       HttpPostedFile file = UploadedFile.PostedFile;
       string fileExt = Path.GetExtension(file.FileName).ToLower();
       string fileName = Path.GetFileName(file.FileName);
       if (fileName != string.Empty)
        {
            
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString =@"Data Source=DEVI\SQLEXPRESS; Initial Catalog =cat; Integrated Security=SSPI";
               
            try
            {
                connection.Open();
                SqlCommand cmd = new SqlCommand("insert into tblphotosettings "
                 + "(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values (@BillNo,@CustomerName,@Address,@StartDate,@EndDate,@Systemurl,@Numberofcopies,@Amount,@Total)", connection);
                cmd.Parameters.Add("@BillNo", SqlDbType.NVarChar).Value = TextBox1.Text;
                cmd.Parameters.Add("@CustomerName", SqlDbType.NVarChar).Value = TextBox2.Text;
                cmd.Parameters.Add("@Address", SqlDbType.NVarChar).Value = TextBox3.Text;
                cmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = Rdbsdate.SelectedDate;
                cmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = Rdbddate.SelectedDate;
                cmd.Parameters.Add("@Systemurl", SqlDbType.VarChar).Value = filename;
                if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
               {
                                                       
                   file.SaveAs(Server.MapPath("D:\photo\images (1).jpg") + fileName);
               }
                cmd.Parameters.Add("@Numberofcopies", SqlDbType.NVarChar).Value = TextBox7.Text;
                cmd.Parameters.Add("@Amount", SqlDbType.NVarChar).Value = TextBox8.Text;
                cmd.Parameters.Add("@Total", SqlDbType.NVarChar).Value = TextBox9.Text;
                cmd.ExecuteNonQuery();
            }
            
            catch (Exception ex)
            {
               throw ex;
            }
         }
        //str = fileName;
        return fileName;
   }
    }
}
}

SQL
  Is it possible web application
my error
    <pre lang="msil">Error   1   Unrecognized escape sequence    C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\photoshops\photoshops\photosetting.aspx.cs 56  51  photoshops

Posted
Updated 4-Apr-11 20:53pm
v3

try this to upload Image to a Folder.

C#
public string fn_UploadImage(FileUpload UploadedFile)
   {
       HttpPostedFile file = UploadedFile.PostedFile;
       string fileExt = Path.GetExtension(file.FileName).ToLower();
       string fileName = Path.GetFileName(file.FileName);
       if (fileName != string.Empty)
       {
           try
           {
               if (fileExt == ".jpg" || fileExt == ".gif" || fileExt == ".bmp" || fileExt == ".jpeg" || fileExt == ".png")
               {

                                                       (Your Path)
                   file.SaveAs(Server.MapPath("~/admin/Upload/Category/") + fileName);

               }
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }
       //str = fileName;
       return fileName;
   }
 
Share this answer
 
Comments
vimal22 2 5-Apr-11 1:58am    
i am begineer please edit in my fully code
vimal22 2 5-Apr-11 2:02am    
i have use file uploadcontrole in asp.net
vimal22 2 5-Apr-11 2:12am    
hi but error
Error 1 Unrecognized escape sequence C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\photoshops\photoshops\photosetting.aspx.cs 56 51 photoshops
The code below
file.SaveAs(Server.MapPath("D:\photo\images (1).jpg") + fileName);

is throwing the error as aspnet account probably does not have write access to the directory specified and also it is better to keep your photo directory inside your app root.
 
Share this answer
 
v2
Comments
Toniyo Jackson 5-Apr-11 5:37am    
Use pre tag for code

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