1

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ページでこの画像にアクセスするにはどうすればよいですか? 私はここで立ち往生しています。私を案内してください。

4

1 に答える 1

1

登録のためにボタンをクリックした後: response.redirect を viewProfile.aspx (または何か) にします。そして持っているasp:image

<asp:Image id="Image1" runat="server"
       AlternateText="Image text"
       ImageUrl="images/noImage.jpg"/>

viewProfile.aspx の Page_Load でデータベースからユーザーを取得し、

Image1.ImageUrl = YourDataRowFromDb["ImagePath"].ToString();

それとも、Asp.Net Web フォームではないでしょうか。

于 2013-07-17T07:48:11.907 に答える