how to get a url of a file with file upload

i want to store the url of a file in database where user uses the fileuplaod to select the file

Then  the url of the file that is chosen should be stored in database

i don't know how t odo this

Can the above be done in this way or is there another way for the solution 



2/16/2009 10:39:47 AM 93655 articles. 6 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 36
Get it on Google Play
Get it on Apple App Store


Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

2/16/2009 11:19:33 AM

Check out this link.

After calling SaveAs() method of FileUpload control, you can save that file path into your database column.



Please mark as answer if you got expected solution.
2/16/2009 11:24:30 AM

I am taking the assumption that u r storing the file on the server  and u need the file path for displaying or making it downloadable.

For this u will be needing to fire a Insert Statement once the file gets uploaded on the server. The file URL can be created using the Code and the proper url for the file can be saved in the db or hold the folder name in which the file is being saved on the server and file name in the format ->

Dim path As String = "foldername/"+FIleUpload.FileName //this will give the File Location on Server

if u Add the URL of the Website using the File Upload with the path of the file the file can be accessed from the server.

i.e. let the name of the site is
then url for file will be

Take Care


2/16/2009 11:35:12 AM
When user select the file using the file upload control you need to store this file in the Server and the path of the file in the database.... to do this... when user click the upload button after selecting the file using fileupload control write the following code in the button click event(Upload button)
if (FileUpload1.HasFile)
string serverPath = Server.MapPath(@"~/images/" + FileUpload1.FileName);
FileUpload1.SaveAs( serverPath);
//Here Write the database logic to store the path in the database (i.e. serverPath string)

2/17/2009 6:56:55 AM

Hi mate,

You can get the file path by below code:

string strPath = System.IO.Path.GetFullPath(FileUpload1.PostedFile.FileName)

Please mark it as answer if this post seems to be useful.
2/17/2009 7:19:44 AM


Try this one

 Attachment : &nbsp;<INPUT type="file" id="txtAttachment" runat="server" NAME="txtAttachment">
                                                          <asp:Button ID="Button1" runat="server" Text="attach me" />

Imports System.IO                          

 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim postedFile = txtAttachment.PostedFile
        Dim strPath As String = ""
        strPath = Path.GetFullPath(postedFile.FileName)

            cmd = New SqlCommand("insert into imgurl values('" & strPath & "')", con)
            cmd.CommandType = CommandType.Text
             Catch ex As Exception
        End Try
    End Sub

2/17/2009 7:31:45 AM

i want relative path from my  application

like /website/foldername/filename.pdf etc

2/17/2009 9:07:19 AM
string UploadDir=Server.MapPath("~/UploadFolder");
strFileName = Path.Combine( UploadDir,FileUpload1.PostedFile.FileName);

Anas Ghanem.

Note:Please Don't hesitate to click "Report Abuse" link if you noticed something wrong on the forums (like duplicate ,Off-topic,offensive,or any post that violates the website "TERMS OF USE"). -- Thanks!

2/17/2009 11:44:01 PM

 If you have already saved the file at /website/foldername/filename.pdf then url will be the same too.

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/website/foldername/filename.pdf">HyperLink</asp:HyperLink>

Make sure, the path where you are saving the file is accessible from the web.

Bind GridView to Dynamically created DataTable | Bind DataTable to DropDownList

My Blog
2/18/2009 1:23:31 AM

Web resources about - how to get a url of a file with file upload -

Wikipedia:File Upload Wizard - Wikipedia, the free encyclopedia
You are not currently logged in. Sorry, in order to use this uploading script and to upload files, you need to be logged in with your named ...

Video On Instagram: 5M Uploads In First 24 Hours
How quickly did Video on Instagram catch on? CNET reported that 5 million videos were uploaded in the first 24 hours after the feature debuted ...

Hans de Borst - Handy-Uploads - Facebook
English version - made by Lennart Peeters. Thank you very much mister Putin, leaders of the separatists or the Ukraine government! For murdering ...

Visit the post for more.

Manage folders and upload files, now in Amazon Cloud Drive
... recent update should cheer you up. The updated version, released on Oct. 10, brings great new features that allow you to manage folders, upload ...

Coming Soon: Facebook Will Ask If You’re Really, Really Sure You Want To Upload That Photo From Last ...
... artificial intelligence knows better: the social media behemoth is working on technology that will warn users when they’re about to upload photos ...

Guy Uploads A Ton Of KMart Background Music To The Internet
... worked at K-Mart. Part of his job was playing pre-recorded cassettes sent in from the corporate office. Luckily for us, he saved them and uploaded ...

Twitch announces VOD feature and video uploads
At it's first-annual TwitchCon, the video-streaming service announced that broadcasters will be able to schedule saved streams and uploaded videos ...

Twitch Users Will Now Be Able To Upload Pre-Recorded Videos
Twitch Users Will Now Be Able To Upload Pre-Recorded Videos

England Uploads Free Digital Model of the Entire Country After Minecraft Players Ask For It
Laser scanning has helped England do everything from discovering new things about Stonehenge to planning better flood infrastructure . Now, the ...

Resources last updated: 12/17/2015 2:07:33 AM