Posting files

D

dana lees

Hi,

I am writing a C# asp.net application.

How can i post files to a web page? Can you please show an example?

I have 3 input files:

for example - <input type="file" size="40" id="file1" runat="server">

and a "load" button:

<asp:imagebutton id="btnLoad" Runat="server"
ImageUrl="../images/btnLoad.gif"></asp:imagebutton>

I would like to load 3 files and post them.

How do i do that?

Thanks,
Dana
 
H

Hans Kesting

Hi,
I am writing a C# asp.net application.

How can i post files to a web page? Can you please show an example?

I have 3 input files:

for example - <input type="file" size="40" id="file1" runat="server">

and a "load" button:

<asp:imagebutton id="btnLoad" Runat="server"
ImageUrl="../images/btnLoad.gif"></asp:imagebutton>

I would like to load 3 files and post them.

How do i do that?

Thanks,
Dana

see
http://msdn.microsoft.com/library/d...mwebuihtmlcontrolshtmlinputfileclasstopic.asp


Hans Kesting
 
O

Onwuka Emeka

Hi Dana,

when you make the <input type="file"....../> HTML control runat server it
becomes a HtmlInputFile control, which has a PostedFile property (which is
a HttpPostedFile object) that contains the uploaded file
you can simply save the file to a destination on your server by calling the
SaveAs(string fileName) method of the HttpPostedFile object. thus:

string fileName=file1.PostedFile.FileName;

FileInfo fileInfo = new FileInfo(fileName);

string newFileName=
string.Concat(Server.MapPath("UploadedFiles"),"/",fName,fileInfo.Extension);

file1.PostedFile.SaveAs(newFileName);



Or you can manipulate the stream object associated with the HttpPostedFile
object if you do not just want to save it. by :



HttpPostedFile post = file1.PostedFile;

byte[] arr = new byte[post.InputStream.Length];

post.InputStream.Read(arr,0,arr.Length);

// your file contents are now int the byte array arr
 
M

Mark Rae

How do i do that?

In addition to the other replies, you need to bear in mind that the default
user under which ASP.NET apps run will almost certainly NOT have write
permission on the server, so you will need to rectify that either by
granting the default user additional permissions or by having your app
impersonate another user which does have those permissions.

Also, if your app is to be hosted on the public internet, make absolutely
certain that your ISP will allow you to do this - not all do...
 
D

dana lees

I don't need to save those files to the server.
I need to post them to another web page.

I know i should cunstruct string similar to the following:

:-----------------------------7d610921440afa Content-Disposition: form-data;
name="req" AddCookieFiles -----------------------------7d610921440afa
Content-Disposition: form-data; name="site_id"
56550 -----------------------------7d610921440afa Content-Disposition:
form-data; name="sitename"
danaarie -----------------------------7d610921440afa Content-Disposition:
form-data; name="siteurl"
http://dsfsdfs -----------------------------7d610921440afa
Content-Disposition: form-data; name="file1"; filename="C:\Documents and
Settings\danal\Desktop\AEG.xls" Content-Type: application/vnd.ms-excel

I have done that in classic ASP before i don't know how to do that with
asp.net
 
B

bruce barker \(sqlwork.com\)

if you are trying to post to another webserver from your asp.net server
code, then look at the webclient class.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top