AsyncFileUpload - Save into DB

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Laine
    New Member
    • Jun 2012
    • 4

    AsyncFileUpload - Save into DB

    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
  • raghurocks
    New Member
    • May 2012
    • 46

    #2
    hai laine

    you can use AsyncFileUpload 1.PostedFile.Fi leName

    dis will solve ur problem if and only you are using IE as browser...

    Comment

    • raghurocks
      New Member
      • May 2012
      • 46

      #3
      Due to security problems we cant get the fullpath of the file in other browsers...hope you understand...

      Comment

      • India777
        New Member
        • Apr 2012
        • 61

        #4
        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.

        Comment

        • Laine
          New Member
          • Jun 2012
          • 4

          #5
          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(Asy ncFileUpload1.F ileName)
          AsyncFileUpload 1.SaveAs(Server .MapPath("Adver tisementImg/") + filename)

          however this doesnt save the image file path into my DB which i needed it to display at another aspx..

          Comment

          • India777
            New Member
            • Apr 2012
            • 61

            #6
            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.
            Code:
            if (IsPostBack && AsyncFileUpload1.PostedFile != null)
                        {
                            DirectoryInfo info = new DirectoryInfo(@"" + Server.MapPath("~/IconImages") + "");
                            if (!info.Exists)
                            {
                                info.Create();
                            }
                            string extension = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName);
                            string filename = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName);
                            string path = "" + info + "/" + filename;
                            AsyncFileUpload1.SaveAs(path);
                            newPreview.ImageUrl = "IconImages/" + filename;
                        }

            Comment

            • Laine
              New Member
              • Jun 2012
              • 4

              #7
              Thanks for ur code :)

              however for dim path as String i got this error:

              Operator '&' is not defined for types 'String' and 'System.IO.Dire ctoryInfo'.

              Comment

              • India777
                New Member
                • Apr 2012
                • 61

                #8
                Check Below is your vb code?

                Code:
                If IsPostBack AndAlso AsyncFileUpload1.PostedFile IsNot Nothing Then
                	Dim info As New DirectoryInfo("" & Server.MapPath("~/IconImages") & "")
                	If Not info.Exists Then
                		info.Create()
                	End If
                	Dim extension As String = Path.GetExtension(AsyncFileUpload1.PostedFile.FileName)
                	Dim filename As String = Path.GetFileName(AsyncFileUpload1.PostedFile.FileName)
                	Dim path__1 As String = "" & info & "/" & filename
                	AsyncFileUpload1.SaveAs(path__1)	
                End If

                Comment

                • Laine
                  New Member
                  • Jun 2012
                  • 4

                  #9
                  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 :)

                  Comment

                  Working...