By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,060 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

AsyncFileUpload - Save into DB

P: 4
Hi, for now im able to save the image into a specific folder using AsyncFileUpload.

However, i've no idea how to save the image filepath into db and display at another aspx of my project which retrieve using image filepath.

Am i in the right track? thanks for your time
Jun 15 '12 #1
Share this Question
Share on Google+
8 Replies


P: 46
hai laine

you can use AsyncFileUpload1.PostedFile.FileName

dis will solve ur problem if and only you are using IE as browser...
Jun 15 '12 #2

P: 46
Due to security problems we cant get the fullpath of the file in other browsers...hope you understand...
Jun 15 '12 #3

India777
P: 61
First You need to save the Image in Your Project Folder then also save the image name in DB. use SaveAs(path) in code behind to Save the File in folder.
Jun 15 '12 #4

P: 4
Hi there thanks for replying.

this is the code i use to save my uploaded image into my folder.

Dim filename As String = System.IO.Path.GetFileName(AsyncFileUpload1.FileNa me)
AsyncFileUpload1.SaveAs(Server.MapPath("Advertisem entImg/") + filename)

however this doesnt save the image file path into my DB which i needed it to display at another aspx..
Jun 16 '12 #5

India777
P: 61
My Sample Code is Below. Please Check it. It may be Help you. You must Submit your page, then only you get Image Path.

This is my c# coading. Please Convert it into vb. Sorry for inconvenience.
Expand|Select|Wrap|Line Numbers
  1. if (IsPostBack && AsyncFileUpload1.PostedFile != null)
  2.             {
  3.                 DirectoryInfo info = new DirectoryInfo(@"" + Server.MapPath("~/IconImages") + "");
  4.                 if (!info.Exists)
  5.                 {
  6.                     info.Create();
  7.                 }
  8.                 string extension = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
  9.                 string filename = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
  10.                 string path = "" + info + "/" + filename;
  11.                 AsyncFileUpload1.SaveAs(path);
  12.                 newPreview.ImageUrl = "IconImages/" + filename;
  13.             }
  14.  
Jun 16 '12 #6

P: 4
Thanks for ur code :)

however for dim path as String i got this error:

Operator '&' is not defined for types 'String' and 'System.IO.DirectoryInfo'.
Jun 16 '12 #7

India777
P: 61
Check Below is your vb code?

Expand|Select|Wrap|Line Numbers
  1. If IsPostBack AndAlso AsyncFileUpload1.PostedFile IsNot Nothing Then
  2.     Dim info As New DirectoryInfo("" & Server.MapPath("~/IconImages") & "")
  3.     If Not info.Exists Then
  4.         info.Create()
  5.     End If
  6.     Dim extension As String = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName)
  7.     Dim filename As String = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName)
  8.     Dim path__1 As String = "" & info & "/" & filename
  9.     AsyncFileUpload1.SaveAs(path__1)    
  10. End If
  11.  
Jun 16 '12 #8

P: 4
hi, yup it is the same but stil having the same error..
hmmm. by the way does your code save the image file path into databasE? im quite confused haha cus how does the system know to store my image file path?
pardon me as im new to vb :)
Jun 16 '12 #9

Post your reply

Sign in to post your reply or Sign up for a free account.