我需要存储文件上传的完整路径,以便我可以检索以在另一个项目中显示。目前它只存储我上传的文件的名称。如何更改它以便存储完整路径?
protected void btn_submit_Click(object sender, EventArgs e) {
string EventName = lbl_eventname.Text;
string FeedbackDesc = tb_description.Text;
int FeedbackRating = Rating1.CurrentRating;
string Image;
string fileName = "";
string desc = tb_description.Text;
BLL_feedback insert = new BLL_feedback();
if (FileUpload1.HasFile) {
Image = "image/" + FileUpload1.FileName.ToString();
fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/image/" + FileUpload1.FileName));
DAL_Feedback feedback = new DAL_Feedback();
int result = 0;
result = feedback.Insert(FeedbackDesc, FeedbackRating, fileName, EventName);
Response.Write("<script>alert('Feedback submitted!');</script>");
}
}
这是我插入数据库的方式:
public int Insert (string desc, int rating, string image, string eventName)
{
StringBuilder sql;
SqlCommand sqlCmd;
int result = 0;
string strConnectionString = ConfigurationManager.ConnectionStrings["HotelDB"].ConnectionString;
SqlConnection myConnect = new SqlConnection(strConnectionString);
string strCommandText = "INSERT Feedback(FeedbackDesc, FeedbackRating, Image, EventName)";
strCommandText += "Values(@FeedbackDesc, @FeedbackRating, @Image, @EventName)";
SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
cmd.Parameters.AddWithValue("@FeedbackDesc", desc);
cmd.Parameters.AddWithValue("@FeedbackRating", rating);
cmd.Parameters.AddWithValue("@Image", image);
cmd.Parameters.AddWithValue("@EventName", eventName);
myConnect.Open();
result = cmd.ExecuteNonQuery();
myConnect.Close();
return result;
}