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 |
![]() |
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 |
![]() |
Check out this link.
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 |
![]() |
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 Serverif 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
Take Care
then url for file will be http://www.abc.com/path
ASIF KHAN
![]() |
0 |
![]() |
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 |
![]() |
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 |
![]() |
Hi,
Try this one
Attachment : <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)
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 |
![]() |
i want relative path from my application
like /website/foldername/filename.pdf etc
![]() |
0 |
![]() |
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 |
![]() |
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
![]() |
0 |
![]() |