-2

my web page is uploading images to server folder which is 'd:\upresim' I adding images with that code:

protected void Button2_Click(object sender, EventArgs e)
{
    FileUpload1.SaveAs(Server.MapPath("~/image/a.png"));
    Image1.ImageUrl = "~/image/a.png";
}

I have a selected image, that I receive from FileUpload that I have added from the selected image to server upresim into folder. Afterwords I need to show the added image on Image1, but it show nothing what can I do?

Ebrar Bayburt
  • 37
  • 1
  • 3
  • 9
  • 1
    _"what can I do"_ - read the manual and show what you have tried. The [Imgae.ImageUrl](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.image.imageurl.aspx) property requires an URL, not a path. Look at the generated HTML in your browser. – CodeCaster Mar 21 '13 at 12:16
  • Resim kaydoluyor mu peki? – Mehmet Ince Mar 21 '13 at 12:19
  • uygulamayı publish edip servera attıktan sonra, uygulama içerisindeki image yani resimlerin ekleneceği klasör publish sırasında saklandığı için resim eklenemiyor ve mage diye bir klasör bulunmuyor şeklibnde bir uyarı veriyor, ben de başka bir klasör gösterdim eklemsi için güvenlikm ayarlarını yaraladım ve şimdi çalışıyor. bu arada yorumlarınız türkçe ya silerseniz yabancılar zorluk çekmesin ben de sizinle konuştuktan sonra silecem – Ebrar Bayburt Mar 21 '13 at 12:35
  • sorry I took your time thank you – Ebrar Bayburt Mar 21 '13 at 12:42

1 Answers1

1

You have to upload images under your web app folder, for that folder your app has to have rigths to write to filesystem, and then set relative url to Image control ImageUrl. You should also check if upload has a file, and preferably use file name from uploaded file.

For example, let's say that you have folder upresim in your web site root folder, then use this code :

  if (FileUpload1.HasFile)
  {
    FileUpload1.SaveAs(Server.MapPath("/upresim/") + FileUpload1.FileName);
    Image1.ImageUrl = "/upresim/" + FileUpload1.FileName;
  }
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
  • I used that ,but when I publish project than the folder is hiding,so the app can not finding the folder and it gives exception – Ebrar Bayburt Mar 21 '13 at 12:18
  • 1
    what exception exactly ? Please update your question with that info. It's not clear what do you mean with "folder is hiding". Do you have that folder on server where you publishing your app ? – Antonio Bakula Mar 21 '13 at 12:23
  • sorry I took your time thank you ,I changed security settings on image folder ,it's working succesfull – Ebrar Bayburt Mar 21 '13 at 12:29