473,379 Members | 1,491 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Posting files

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
May 1 '06 #1
5 1308
> 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/de...classtopic.asp
Hans Kesting
May 1 '06 #2
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

"dana lees" <da***@idc.ac.il> wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
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

May 1 '06 #3
"dana lees" <da***@idc.ac.il> wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
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...
May 1 '06 #4
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
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
"dana lees" <da***@idc.ac.il> wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
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...

May 1 '06 #5
if you are trying to post to another webserver from your asp.net server
code, then look at the webclient class.

-- bruce (sqlwork.com)

"dana lees" <da***@idc.ac.il> wrote in message
news:uS**************@TK2MSFTNGP03.phx.gbl...
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
"Mark Rae" <ma**@markN-O-S-P-A-M.co.uk> wrote in message
news:%2***************@TK2MSFTNGP02.phx.gbl...
"dana lees" <da***@idc.ac.il> wrote in message
news:ec**************@TK2MSFTNGP05.phx.gbl...
> 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...


May 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Randell D. | last post by:
Folks, Sorry for the cross post into multiple newsgroups on this, but html forms processing is supported across all three groups so I was hoping someone might know. I did a check with Google...
0
by: Laphan | last post by:
I know this is a crosspost, but I need to know which is the best one for posting INET FTP queries, so that I'm not cross-posting in future. Now that I've posted could somebody let me know: 1)...
13
by: Ian.Suttle | last post by:
I am have been researching this issue to no end, so any help would be very much appreciated. I have a page with form tags. Inside of the form tags is a panel that contains a user control. The...
4
by: Jason Penniman | last post by:
Here's an interesting one that has me stumped. I have several ASP.NET applications writen in VB.NET that stopped posting back on click of a button. Nothing has changed in the code or the...
2
by: m | last post by:
Hi All, I m extremely sorry if this is the wrong place to post it but i just need some info on the MS Posting Acceptor. 1) Is MS Posting Acceptor available with IIS5.0 and above. 2)If so where...
2
by: Rabbit | last post by:
Dear All, I've been tried various configuration and did install SP1 on Windows 2003 Server. The problem now that I have is an aspx page located on the web site for taking the file post by...
0
by: Rabbit | last post by:
Dear all, My application contains 2 parts(Server and Client), the server side is having a ASP.net page as listener for client side to post file, the main coding to receive posting file as...
43
by: balakrishnan.dinesh | last post by:
Hi all, Im working in javascript, I want to use Ajax in javcascript, Can u tel me how to use ajax in javascript, whether i have to include any code as like to include *css or *.js file, what are...
2
by: athos | last post by:
OS: Windows 2000/XP (needs to run on 2 different machines) Language: Python 2.5 Programmer Level: Pathetically new to Python Goal: Using code I've altered for my needs, I'm attempting to create...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.