C#与ASP.NET与SQL Server2005 [英] c# with asp.net with sql server2005

查看:58
本文介绍了C#与ASP.NET与SQL Server2005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计我的网页,我想要存储图像位置,然后进行客户记录,我正在做照相馆管理工作室系统图像位置而不是存储...

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;
   }
    }
}
}


  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


推荐答案

尝试将其上传到文件夹中.

try this to upload Image to a Folder.

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;
   }


下面的代码
The code below
file.SaveAs(Server.MapPath("D:\photo\images (1).jpg") + fileName);


发生错误,因为aspnet帐户可能没有对指定目录的写权限,因此最好将照片目录保留在应用程序的根目录下.


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.


这篇关于C#与ASP.NET与SQL Server2005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆