我使用此代码将图像上传到服务器。是它的工作。但我需要将图像路径发送到我的数据库。我有一个带有 Profiles 表和 ImagePath 字段的数据库。
我怎样才能做到这一点...
我的工作代码在这里
public partial class ProfileDetails2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void upload_Click(object sender, EventArgs e)
{
int intFileSizeLimit = 10;
string strFileNameWithPath = FileUpload1.PostedFile.FileName;
string strExtensionName = System.IO.Path.GetExtension(strFileNameWithPath);
string strFileName = System.IO.Path.GetFileName(strFileNameWithPath);
int intFileSize = FileUpload1.PostedFile.ContentLength / 1024;
strExtensionName = strExtensionName.ToLower();
if (strExtensionName.Equals(".jpg") || strExtensionName.Equals(".gif"))
{
if (intFileSize < intFileSizeLimit)
{
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/images/") + "img" + strExtensionName);
lblMessage.Text = "Uploaded file details <hr />" +
"File path on your Computer: " + strFileNameWithPath + "<br />" +
"File Name: " + strFileName + "<br />" +
"File Extension Name: " + strExtensionName + "<br />" +
"File Size: " + intFileSize.ToString();
}
else
{
lblMessage.Text = "File size exceeded than limit " + intFileSizeLimit + " KB, Please upload smaller file.";
}
}
else
{
lblMessage.Text = "Only .jpg or .gif file are allowed, try again!";
lblMessage.ForeColor = System.Drawing.Color.Red;
}
}
}