C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




To upload Documents like(doc,pdf,etc) to file system


Posted Date: 10 Jul 2006      Total Responses: 2

Posted By: nagarjuna.p       Member Level: Bronze     Points: 2


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

Author: santhosh punnam    10 Jul 2006Member Level: BronzeRating:     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




Author: banu    22 Oct 2008Member Level: SilverRating:     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..



Post Reply
You must Sign In to post a response.
Next : Please tell me .Net interview Questions for 2+ Years Exp
Previous : Regarding Datagrid
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

doors in nj

Contact Us    Privacy Policy    Terms Of Use