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 

 

 

0
anshuman
2/16/2009 10:39:47 AM
📁 asp.net.web-forms
📃 93655 articles.
⭐ 1 followers.

💬 9 Replies
👁️‍🗨️ 217 Views

http://aspnet.4guysfromrolla.com/articles/120606-1.aspx


Regards,

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!

0
anas
2/16/2009 11:19:33 AM

Check out this link.

http://www.c-sharpcorner.com/UploadFile/mahesh/FileUpload10092005172118PM/FileUpload.aspx?ArticleID=79850d6d-0e91-4d7b-9e27-a64a09b0ee6b

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

 


Thanks,
santosh_maharaja

Please mark as answer if you got expected solution.
0
santosh_maharaja
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 http://www.abc.com
then url for file will be http://www.abc.com/path

Take Care

 


ASIF KHAN
0
khanasif1
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)
}

Chinna_sv...
0
getchinna_sv
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.
0
nishit_123
2/17/2009 7:19:44 AM

Hi,

Try this one

 Attachment :  
                                                         
                            
-------------

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)
        Response.Write(strPath)

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

0
raja2482
2/17/2009 7:31:45 AM

i want relative path from my  application

like /website/foldername/filename.pdf etc

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

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!

0
anas
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.

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
0
shahed
2/18/2009 1:23:31 AM