1
朋友我需要您的幫助來解決問題。ASP.NET和存儲過程中的FileUpload控件問題
DETAIL 我有一個基於更新面板(幻燈片作品),其中一張幻燈片要求用戶上傳他/她的照片(可選)上的報名表格。
發行 一切正常,精細名稱保存在數據庫中,用戶文件夾中創建在服務器端,但該文件沒有上傳...沒有錯誤。
碼
@primePhoto - FileUpload1
protected void RegisterClick6(object sender, EventArgs e)
{
string pathToCreate = "img/users/" + userName.Text;
if (Directory.Exists(Server.MapPath(pathToCreate)))
{
}
else
{
Directory.CreateDirectory(Server.MapPath(pathToCreate));
}
String imageFolder = pathToCreate;
String savePath;
String saveFile;
if (FileUpload1.HasFile)
{
savePath = Path.Combine(Request.PhysicalApplicationPath, imageFolder);
saveFile = Path.Combine(savePath, FileUpload1.FileName);
FileUpload1.SaveAs(saveFile);
}
SqlConnection con = new SqlConnection(str1);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "RegisterUser";
cmd.Parameters.AddWithValue("@userName", userName.Text);
cmd.Parameters.AddWithValue("@email", Email.Text);
cmd.Parameters.AddWithValue("@postDate", currentDate.Text);
cmd.Parameters.AddWithValue("@password", Password.Text);
cmd.Parameters.AddWithValue("@FirstName", FirstName.Text);
cmd.Parameters.AddWithValue("@LastName", LastName.Text);
cmd.Parameters.AddWithValue("@primePhoto", FileUpload1.FileName);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
multiview1.SetActiveView(view7);
}
您是否使用表單標籤? enctype =「multipart/form-data」如下:
不,我不知道它 –
好吧,我做到了,但仍然沒有結果:( –