Problem in Receiving the files that had been attached with my web form using a html file input

Hello there!,

I am having trouble in receiving the attached files from a html file input !.

First of all i have added a master page and made this form as a content page!

Actaully the view state of this html file input is not maintaining when the page is posted back!. It says Request.Files.Count=0 even i had attached a file!

Before adding the master page it worked fine!

Could you please tell me a solution!,
My Code is

if (Request.Files.Count != 0)
{
HttpFileCollection files = Request.Files;
DataTable Table4 = new DataTable();


DataColumn Doc_Name = new DataColumn();
Doc_Name.ColumnName = "Documents";

DataColumn Remove = new DataColumn();
Remove.ColumnName = "Remove";

Table4.Columns.Add(Doc_Name);

Table4.Columns.Add(Remove);
for (int p = 0; p < files.Count; p++)
{
HttpPostedFile file = files[p];

if (file.ContentLength == 0)
{
continue;
}
string c = System.IO.Path.GetFileName(String.Format(file.FileName));

string path = Server.MapPath("../")+"Upload"+ @"\" +c;


StreamWriter streamWriter;
streamWriter = File.CreateText(path);
streamWriter.Close();

file.SaveAs(path);

Table4.Rows.Add(p);

Table4.Rows[p]["Documents"] =c;
Table4.Rows[p]["Remove"] = "Remove";

}
Session["DOC_INFO"] = Table4;
}

Much Obliged & Thanks a Lot,
Myself
0
Sidewinder2
8/23/2008 4:55:12 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

2 Replies
948 Views

Similar Articles

[PageSpeed] 40

Because the FileUpload's FileName property is a read-only when and for security reasons, Once a postback happens the fileupload control will not save the previous user selection.

As for the Master Page, you should use break points and debug your code to see what exactly is happening and in case you didnt get to solve it, reply to this thread by giving more information

 


Haissam Abdul Malak
MCAD.NET
| Blog |
0
Haissam
8/23/2008 10:20:01 AM

The answer is add the following code in the master page!,

 

if (Request.Files.Count != 0)

{

HttpFileCollection files = Request.Files;DataTable T1 = new DataTable();

 

DataColumn Doc_Name = new DataColumn();

Doc_Name.ColumnName = "Documents";

DataColumn Remove = new DataColumn();Remove.ColumnName = "Remove";

T1.Columns.Add(Doc_Name);

T1.Columns.Add(Remove);

 

if (Session["INFO"] == null)

{

for (int p = 0; p < files.Count; p++)

{

HttpPostedFile file = files[p];if (file.ContentLength == 0)

{

continue;

}

string c = System.IO.Path.GetFileName(String.Format(file.FileName));string path = Server.MapPath("../") + "Upload" + @"\" + c;

 

StreamWriter streamWriter;streamWriter = File.CreateText(path);

streamWriter.Close();

file.SaveAs(path);

T1.Rows.Add(p);

T1.Rows[p][
"Documents"] = c;T1.Rows[p]["Remove"] = "Remove";

}

Session[
"INFO"] = T1;

}

else

{

DataTable T2 = new DataTable();

T2 = (DataTable)Session["INFO"];

int var = T2.Rows.Count;

int tot = (int)(var + files.Count);

int p = 0;for (int m = T2.Rows.Count; m < tot; m++)

{

HttpPostedFile file = files[p];if (file.ContentLength == 0)

{

continue;

}

string g = System.IO.Path.GetFileName(String.Format(file.FileName));string path = Server.MapPath("../") + "Upload" + @"\" + g;

 

StreamWriter streamWriter;streamWriter = File.CreateText(path);

streamWriter.Close();

file.SaveAs(path);

T2.Rows.Add(m);

T2.Rows[m][
"Documents"] = g;T2.Rows[m]["Remove"] = "Remove";

p = p + 1;

}

Session[
"INFO"] = T2;

}

}

  because when we clickthe save button the control passes to the master page and then only it comes to the content page!


Much Obliged & Thanks a Lot,
Myself
0
Sidewinder2
8/25/2008 7:28:51 AM
Reply:

Similar Artilces:

WEB FORMS and datasetS (do I have to repeat the file definition in every web form?)
I am working on vb.net.I have a project with 35 web forms and an access file with 18 tables.Until now I have defined the oledbadapters in every form by dragging the tables from the server explorer tool box.This is not a good idea because every time that I make a change on the database design I have to drag the new definition on 35 web forms and I have to create the datasets again. This is boring and time consuming!The question is:WHAT CAN I DO TO HAVE THE FILE DEFINITION ONLY IN ONE PLACE AND THAT EVERY WEB FORM WOULD TAKE THE DATA ADAPTERS AND DATASETS FROM THERE? how about if you write a...

How to add html file input in a web form through jscript?
Hello Mate,                    I just want to add Html file input in a web form at runtime after when i click a button . Actually i have a button called "Attach" and when i click this button once then one Html file input should be shown when i click the button again then one more Html file input should be added below the existing Html input .If you have any idea regarding this ,please let me know Thanks in Advance!,Much Obliged & Thanks a Lot,Myself You may get some ideas from here...

Is there a way to automate uploading file in a web page using html file input control?
I used a form with a web browser control on it to automate the process of connecting to a website entering the login and password and finish the process of uploading a file.As you navigate to the upload page i can't get the input file control to work automatically because the value property is read only and here is the code HtmlDocument loginPage = wb.Documanet;loginPage.All["file1" ].SetAttributes("value", @"C:\A\A.txt");              //this doesn't work Your help is appreciated. Mark as an answer if it helps. ...

Users using File>Save as> to save form as .html file no longer saving form data any reason??
I have been building an asp.net 1.1 webpage for some time now and my users have been able to go in pull up a record from the database which is loaded into lable / textbox fields. My users have been able to pick File --> Save As --> HTML and it would save the whole page with the data saved in the forms.  The users could then open the as standalone and while the form was no longer interactive they were still able to view the data in the fields at the time of the save.  Now when they save it only saves the form, and none of the lables or data. My users use Internet Explorer ...

Access web form content from client side HTML file using javascript
I have two browser windows open, one an html file residing on the client and one an aspx page served up by the web server. Neither window is related to the other; neither one opened the other. Is it possible for javascript on the html file which resides on the user's local computer to "read" any of the information from the other open window? Ideally, I'd like to read a hidden input field from the web page. The solution only has to work in IE 6 and 7. Thanks in advance. Man, this sounds more like a virus, like spyware... Why do you need to do such thing? What I want is to open ne...

can someone one give me difference between web form and mobile web form and which or where or when i'm using the forms?
thanks Marc Hi Marc, Based on my understanding, you want to know the differences between the ASP.NET web application and ASP.NET mobile web application. If I have misunderstood you, please feel free to let me know. The ASP.NET forms are used to develop the ASP.NET pages for desktop browsers and The ASP.NET mobile forms are used to develop the ASP.NET pages for mobile device browsers. When we create the ASP.NET mobile web forms pages, we can use nearly all the features of ASP.NET. But there are a couple of compatibility issues: Error Handling and Reporting. Tracing. Using Redi...

Web Service Logging To File Problem (file in use)
I have a web service that does a bunch of processing and when complete I would like it to write to a text file log in IsolatedStorage.  I'm using the FileStream and StreamWriter and am getting the following error periodically: The process cannot access the file "C\inetpub\wwwroot\serv\IsolatedStorage\RequestLog.txt" because it is being used by another process. The code looks like this:         Dim fStreamWriter As StreamWriter         Dim fsFile As FileStream         f...

Web form that can attach files
Hie all I have created a form on my web site and I would like users to be able to attach files on it so that when they submit, it will be directed to my email address. Thanks Ntini Hi, Take a look @ - Uploading In ASP.NET - Sending Email from an ASP.NET Web Page HTHK B ShajudeenAreYaar.comDubai, United Arab Emirates....

Web forms and mobile web forms
Hey everyone, I am looking to develope a web site that depending on the device connecting to it, it will display a certain page. In this case im looking to create a web and wap version of the same project. I have the Web forms version finished using ASP.NET and C# and I am wondering how to create the mobile web form and incorporate it in the project. In the project folder, can I just add a mobile web??? But what about displaying device specific pages?? Cheers -Dudach Yes, you can add mobile web forms and controls to your Web Application project. No problem. For device/br...

How to Make Web Forms from other Web Forms
In putting together an ASP.NET application for a biz application, we have come to the point where there are three different types of basic forms which have, for the most part, been perfected. Now its is a matter of cloning those forms for various uses and modifying or adding code to suit the particular need. Copy and paste works OK, but there is a lot of changing of certain words, etc. Is there a way in ASP.NET to take these basic forms, turn them into classes or templates, create forms from them, then add or overwrite code? ? (Anybody who is a Vis Fox Pro programmer would know imme...

Need Windows Form to Retrieve Information From Web Form
I have a cash and carry web site that customers can order products, the next day come in to the company to pay and pickup. I would like to create a windows application for the company to do two things: 1. download all the orders from the day before 2. upload price changes, product changes, category changes I've search the internet and forums and the only thing I can find that I think would actually link these two together would be a web service. Can you please tell me if I am heading in the right direction or if there is another method to link the two applications, if there are any pitf...

How to insert audio files and play audio files in a web form
Hi, 1) Could you please post a sample code which shows how to save an audio file and play an audio file from server? 2) Which of the following way is better for performance?         a) Save the audio file to a folder in the server and save the name of the file in database.         b) Save the audio file directly to database in binary format. Requirement is that Many people will be accessing the site and the same file at the same time. If anybody has any code for saving and playing audio file,...

how to read a .txt file from .net (web form)
hi, how to read a .txt file line by line and place the contents in a .xls file. ex: if sample.txt file is... Name: abc Company: xyz info ltd. i want abc and xyz info ltd to be cut and saved in .xls file. i already have a .xls template with name and company fields. send solution.......

The file could not be loaded into the Web Forms designer PROBLEM
the HELP for this error is: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbref/html/vberrthefilecouldnotbeloadedintowebformsdesigner.asp but I still can not fix it I have OWN CLASS , I do reference and all is corect the Site working but I still can not access to DESIGN MODE It is give me error: WebForm -- The base class "MyCommonWebDLL.baseForm" cound not be loaded. Ensure the assembly has been referenced or built if it is part ot the project. Make sure all of the classes used in the page are build or referenced in the project. valhttp://www...

Web resources about - Problem in Receiving the files that had been attached with my web form using a html file input - asp.net.web-forms

Commercial mail receiving agency - Wikipedia, the free encyclopedia
A commercial mail receiving agency ("CMRA"), also known as a mail drop, typically operates as a Private Mail Box Operator. A customer of a CMRA ...

Underwriters Begin Receiving Their Shares Of Facebook IPO Profits
Lead underwriter Morgan Stanley began doling out the $100 million or so in profit earned by banks as a result of Facebook’s initial public offering ...

Texas Tribune - To stop Planned Parenthood from receiving... - Facebook
To stop Planned Parenthood from receiving public financing, Texas’ Republican leaders gambled that the state could operate the Women's Health ...

Receiving Money (@richardatdell) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Giving and receiving thanks
That most American holiday, Thanksgiving, is upon us. Lots of you are turning to Twitter to express gratitude for the things you feel most grateful ...

Shipping & Receiving - Flickr - Photo Sharing!
Some cargo containers at the International Marine Terminal on Commercial Street. Corey Templeton Photography - Portland Daily Photo - Facebook ...

Nicholas Merrill Speaks Out About Receiving a National Security Letter - YouTube
The first rule of national security letters? You can't talk about national security letters. THUMBS UP for protecting the freedom of speech and ...

More children receiving psychological care at Dubai hospital
... counselling department at Latifa Hospital in Dubai since the beginning of this year, 157 cases were new. DUBAI // The number of children receiving ...

George Christensen blames Bill Shorten for 'fanning violence' after receiving death threat over controversial ...
Government backbencher George Christensen says he has received a death threat following comments he made about the federal budget and has accused ...

Facebook Email Addresses - Users Not Receiving Mail Issue
Facebook: we're fixing email and address book issues

Resources last updated: 12/27/2015 6:47:49 PM