我正在 c# 中创建一个用户帐户(useraccount.aspx)页面。一旦用户单击注册页面(userregistration.aspx)中的提交按钮,我必须显示帐户页面。我已将用户图像上传到我的应用程序中的一个文件夹,并且图像路径保存在我的数据库中。请在我的用户注册页面中找到用于上传用户图像的代码。
string filename = Path.GetFileName(fuUploadPhoto.PostedFile.FileName);
if (fuUploadPhoto.HasFile)
{
if (fuUploadPhoto.PostedFile.ContentType == "image/jpeg")
{
fuUploadPhoto.SaveAs(Server.MapPath("~/PhotoCollection/" + filename));
try
{
objcon.Open();
SqlCommand cmd = new SqlCommand("Insert into ImagesPath(ImageName,ImagePath,userName) values(@ImageName,@ImagePath,@userName)", objcon);
cmd.Parameters.AddWithValue("@ImageName", filename);
cmd.Parameters.AddWithValue("@ImagePath", "~/PhotoCollection/" + filename);
cmd.Parameters.AddWithValue("@userName", txtDesiredUserName.Text.ToString());
cmd.ExecuteNonQuery();
}
catch (Exception exc)
{
}
finally
{
objcon.Close();
lblPhoto.Text = "Photo uploaded successfully";
}
}
else
{
lblPhoto.Text = "Uploaded image is not of correct format";
}
}
else
{
lblPhoto.Text = "Please upload an image";
}
现在我如何在 useraccount.aspx 页面中访问此图像?我被困在这里。请指导我。