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
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.
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.comTake Care
then url for file will be http://www.abc.com/path
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)
string serverPath = Server.MapPath(@"~/images/" + FileUpload1.FileName);
//Here Write the database logic to store the path in the database (i.e. serverPath string)
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.
Try this one
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
i want relative path from my application
like /website/foldername/filename.pdf etc
string UploadDir=Server.MapPath("~/UploadFolder"); strFileName = Path.Combine( UploadDir,FileUpload1.PostedFile.FileName); FileUpload1.PostedFile.SaveAs(strFileName);
If you have already saved the file at /website/foldername/filename.pdf then url will be the same too.
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