我试图使用 c# 将图像添加到目录中。我将使用此图像在网格视图中显示。我写了代码,但我遇到了一个错误,我无法解决它。我有一个名为图像的目录。这是我收到错误 FileUpload1.SaveAs (Server.MapPath("images/" + FileName). 它说 C:\Users\user\Documents\Visual Studio 2008\WebSites\WebSite1\images\im1.jpg' 部分找不到路径。这是我的代码:
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("images/" + FileName));
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
string strQuery = "INSERT INTO Books (Book_Name,Author_Name,FileName, FilePath, In_Lib) VALUES (@BN,@AN,@FileName, @FilePath,@LIB)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@BN", TextBox1.Text);
cmd.Parameters.AddWithValue("@AN", TextBox2.Text);
cmd.Parameters.AddWithValue("@FileName", FileName);
cmd.Parameters.AddWithValue("@FilePath", "images/" + FileName);
cmd.Parameters.AddWithValue("@LIB", "YES");
cmd.CommandType = CommandType.Text;
cmd.Connection = con;