|
Forums » .NET » ASP.NET »
|
To upload Documents like(doc,pdf,etc) to file system |
Posted Date: 10 Jul 2006 Posted By:: nagarjuna.p Member Level: Bronze Member Rank: 0 Points: 2
Responses:
3
|
Here iam sending some code, i need the rest of the code for it.
Here iam sending code to upload Document, that i coded in Doc.aspx page <table> <tr align="center"><td><h4>Select document you want to upload</h4></td></tr> <tr align="center"><td><input id="uploadDoc" runat="server" type="file" /></td></tr> <tr align="center"><td><asp:Button ID="Button1" runat="server" Text="Upload" Width="94px" OnClick="Button1_Click" /></td></tr> </table>
Code in Doc.aspx.cs file public void Button1_Click(Object sender, EventArgs args) { HttpPostedFile myFile = UploadDoc.PostedFile; Upload up = new Uplaid(); up.Click(myFile); }
I need code for Upload.cs file
|
Responses
|
#62478 Author: santhosh punnam Member Level: Bronze Member Rank: 0 Date: 10/Jul/2006 Rating:  Points: 2 | i will send total code please follow these instructions
take new proj in asp.net and go to html view copy the follwoing code
<HEAD> <TITLE>File Download</TITLE> </HEAD> <body leftMargin="0" topMargin="0" marginwidth="0" marginheight="0"> <form id="frmDownload" method="post" runat="server"> <table cellSpacing="0" cellPadding="0" width="100%" border="0"> <tr> <td align="center"><IMG src="images/up.gif"> </td> </tr> </table> <table width="90%" align="center" border="0"> <tr> <td align="center"> </td> </tr> <tr> <td class="PageHeading" align="center">File Download (VB) </td> </tr> <tr> <td><IMG height="10" src="images/spacer.gif" border="0"></td> </tr> <tr> <td align="center"> <asp:ListBox ID="lstFiles" Runat="server" Rows="6" /> </td> </tr> <tr> <td align="center"> <br> <input id="btnDownload" runat="server" type="button" value="Download" NAME="btnDownload"> </td> </tr> </table> </form> </body>
go to code behind import name space imports System.io
Dim files() As String
page_load
Dim index As Integer
If (Not Page.IsPostBack) Then
'get list of files in the images directory (just for example here)
'files = Directory.GetFiles(Server.MapPath("images")) files = Directory.GetFiles("C:\test")
'for display purposes, remove the path to the file
For index = 0 To files.Length - 1
files(index) = New FileInfo(files(index)).Name
Next index
'bind the list of files to the listbox on the form
lstFiles.DataSource = files
lstFiles.DataBind()
'select the first entry in the list
'NOTE: This is done to simplify the example since preselecting an
' item eliminates the need to verify an item was selected
lstFiles.SelectedIndex = 0
End If
End Sub
btnDownload_ServerClick
Dim file As FileInfo
Dim filename As String
'get the fully qualified name of the selected file
filename = "C:\test" & "\" & lstFiles.SelectedItem.Text()
'get the file data since the length is required for the download
file = New FileInfo(filename)
'write it to the browser
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment; filename=" & lstFiles.SelectedItem.Text)
Response.AddHeader("Content-Length", file.Length.ToString())
Response.ContentType = "application/octet-stream"
Response.WriteFile(filename)
Response.End()
End Sub
and create folder in cdrive name as test and go to solution explorer create new folder add images names file.gif, up.gif, upload.gif then execute the code if you any dout please dont hesiteate send to me
| #309502 Author: banu Member Level: Silver Member Rank: 1959 Date: 22/Oct/2008 Rating:  Points: 5 | if (upload.FileName != "") { objNewuserregprop.fileupload = upload.FileName; string img = Server.MapPath("~/fileupload/"); upload.PostedFile.SaveAs(img + upload.FileName); }
add file folder in your solution explorer..here my file folder is fileupload..if u upload any files in output then it will store in database and also in this folder..
if u got the answer tell me..
| #330728 Author: Jayesh Member Level: Gold Member Rank: 721 Date: 18/Dec/2008 Rating:  Points: 2 | Instead you can use a FileUpload control.
in the Button_Click event you can write the following code
FileUpload1.SaveAs("yourfilename (full path)");
eg. FileUpload1.SaveAs(Server.MapPath("Images") + "/" + FileUpload1.FileName);
-Jayesh
Jayesh K.S.
|
|
| Post Reply |
|
|
|
 | | This thread is locked for new responses. Please post your comments and questions as a separate thread. If required, refer to the URL of this page in your new post. |
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|