When I upload a text file from client to server using stream, how can I guarantee that the uploaded text file can be displayed correctly?

When I upload a text file from client to server using stream, how can I guarantee that the uploaded text file can be displayed correctly?


A user want to upload a text file from client PC to server (normally it is Windows 2003), but I'm not sure which OS it is in client, maybe it is a english version Windows or chinese Windows (default encoding is GB2312).
so the encoding of text file in client maybe is ASCII or GB2312.
I think that "StreamReader myRead= new StreamReader(FileUpload1.PostedFile.InputStream,Encoding.Default) will be run in server,
so "Encoding.Default" will be the default encoding of Windows 2003 server, if the default encoding of the Windows 2003 server is english encoding,
a uploaded text file with GB2312 encoding will be displayed correctly (I think), how can I guarantee that the uploaded text file can be displayed?
I think if the server can know the encoding of client which upload file, the program in server can replace "Encoding.Default" with "Client Encoding",
so no matter which OS the client is, the uploaded text file always can be displayed correctly in server!

Any ideas for me, many thanks!

 

 


//------------------------------------Upload program--------------------------------------------------------------------
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

  protected void UploadButton_Click(object sender, EventArgs e)
  {

    String savePath = Server.MapPath("~/upload/");
 

    if (FileUpload1.HasFile)
    {
      String fileName = FileUpload1.FileName;

      savePath += fileName;

      System.IO.StreamReader myRead= new System.IO.StreamReader(FileUpload1.PostedFile.InputStream,Encoding.Default);
      System.IO.StreamWriter myWrite = new System.IO.StreamWriter(savePath, false, Encoding.Unicode);

      string line = myRead.ReadLine();
       
      while (line != null)
      {
          myWrite.WriteLine(line);
          line=myRead.ReadLine();         
      }
       
      myWrite.Close();
      myRead.Close();
   

      UploadStatusLabel.Text = "Your file was saved as " + fileName;
    }
    else
    {     
      UploadStatusLabel.Text = "You did not specify a file to upload.";
    }

  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>FileUpload Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
       <h4>Select a text file to upload:</h4>
  
       <asp:FileUpload id="FileUpload1"                
           runat="server">
       </asp:FileUpload>
           
       <br /><br />
      
       <asp:Button id="UploadButton"
           Text="Upload file"
           OnClick="UploadButton_Click"
           runat="server">
       </asp:Button>   
      
       <hr />
      
       <asp:Label id="UploadStatusLabel"
           runat="server">
       </asp:Label>       
    </div>
    </form>
</body>
</html>
//---------------------------------------Upload program------------------------------------------------------------------


SuperCool Multiple ZIP - A utility to unzip multiple files and work with multiple zip files

SuperCool Random Number Generator
0
mycwcgr
10/31/2005 1:33:36 AM
asp.net.web-dev-2005-express 3977 articles. 0 followers. Follow

0 Replies
1592 Views

Similar Articles

[PageSpeed] 29

Reply:

Similar Artilces:

upload picture file.. i can do it.. but how can i display picture loading to button1.text after i click button1 ???
hello friends i have 5 image that image1 and image2 etc. i also have fileupload1 and button1 and i can upload 5 pictures with one fileupload1 and one button1.. my code is below..but i want to display picture uploading to button1.text :) normally button1.text display picture load but button1.text should be displayed picture loading after i click button1  while picture is uploading :) button1.text should be displayed picture load again after picture uploaded how can i do this ? cheersProtected Sub Button1_Click(ByVal sender As Object, ByVal e As System....

without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible?
without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible? avdp211:without server side scripting, can we upload a file using client side scripting if destination folder and config file settings are known? is it possible? I don't think it is possible.You use the the HTML input file control and when you post the request, on the web server you need to read the data and save it to a file, so there has to be some interaction with the server to handle the post request.  Not possible vi...

Is there any limitation of file types that file upload control can be used to upload?
I am working on a content management system which requires me to upload WebEx recording files (.wrf) through file upload control. But I am getting "internet explorer cannot display the webpage" error. It worked with other files types as txt, doc, xls, pdf, jpg, gif etc. Is it related to any security issue or just a bug with the file upload control?  Thank you. The file upload control doesn't have any file type limitations that I'm aware of, but it does have some size constraints.  By default, ASP.NET is configured to not accept any file's larger than 4...

file uploader save file on server and in database and upload this file on client
hi,i have a file uploader control user can attach files (.rar, .zip, etc) and store file folder and path in database. and another user can click of attach link and can download that file. how can i do this please solve out this problem. you can find your problem solution in this link and you can store the file name in your database server.http://www.aspnettutorials.com/tutorials/network/net-fileupload-aspnet2-csharp.aspxPlease Mark as Answred If This Blog has Helped You.RegardsMitesh Darjihttp://www.indianic.comhttp://www.mitatdotnet.blogspot.com As always there are many ways and which ...

How can I uplaod image file to SQL server and display uploaded files
This is my first time to create web site by using Visual web developer express 2005. I want to create company's activity member profile web page by use sql database. But I don't know how to create SQL DB and Table and I don't know code for connect to sql server, code for upload image files, data file, and code for displays images. So please tell me how to do it step by step. (I use VS web developer express 2005 with vb.net) Thank you  this link should help http://www.dotnetspider.com/kb/Article1935.aspxhttp://dot-net-search-engine.swicki.com/how+to+upload+image+...

Uploading data to sql server 2005 express database from a text file
Hi, (1)  Is there any free tool to Upload data to sql server 2005 express database from a text file? (2) Is there any free export / import data tool for sql server 2005 express? Regards,Sandyhttp://www.thequinn.infohttp://www.sksdataservices.comhttp://www.infobasket.info...

Can it auto download files and upload files to and from client side computer from server pages(aspx)?
P.S. I am using C# project. In case ,There are 4 xml files in my server computer. My pages are <http://www.abc.com/upload.aspx> and <http://www.abc.com/download.aspx> on server if my server is <http://www.abc.com>. They are used for uploading and downloading process. Question 1 : Can I copy that 4 xml files to the specified folder (eg. C:\XML\ ) on client computer by clicking a button "Download" in the page , <http://www.abc.com/download.aspx>?, which means that people no need to click "save as" to the download these 4 xml file...

how can i upload file in sql server 2005 express and login control issues.
  Some issues:1.I wanna upload files to the sql server using a file upload control. I dont have any idea wht datafields would be in my database table, i also want to know how can i associate the specific file with each mail message in my project, i.e how can i implement the attachment issue in my mail server. i also want the user to have liberty of uploading stuff upto 5MB of size only and in only specific extensions. I also wanna provide some download mechanism in order to view files. How can i do that?2. How can I retrieve user name and password from a default table which was mad...

How can I select a directory from client machine, then upload all Image file to the Web Server?
Hello All, How can I select a directory from client machine, then upload all Image file to the Web Server? I can not find a control such as "Folder Explorer", the control "FileUpload" can onlu select and upload one file.  Thanks Simply put, you cannot do this.  That is unless you are going to use ActiveX control.  This is because web applications are untrusted.  The user has to initiate the action to upload the file and that too one at a time.  But you can fake multiple file uploads.  Google it.  Here is an excellent articl...

superreview requested: [Bug 24867] UI for FTP upload not implemented : [Attachment 145537] modify the uploading method and dialog. now it can upload files both to ftp server and webdav server.
ZF.Dang <dantifer.dang@sun.com> has asked for superreview: Bug 24867: UI for FTP upload not implemented http://bugzilla.mozilla.org/show_bug.cgi?id=24867 Attachment 145537: modify the uploading method and dialog. now it can upload files both to ftp server and webdav server. http://bugzilla.mozilla.org/attachment.cgi?id=145537&action=edit ------- Additional Comments from ZF.Dang <dantifer.dang@sun.com> Darin, please take time to have a look. ...

superreview cancelled: [Bug 24867] UI for FTP upload not implemented : [Attachment 145537] modify the uploading method and dialog. now it can upload files both to ftp server and webdav server.
Darin Fisher (IBM) <darin@meer.net> has cancelled ZF.Dang <dantifer.dang@sun.com>'s request for superreview: Bug 24867: UI for FTP upload not implemented http://bugzilla.mozilla.org/show_bug.cgi?id=24867 Attachment 145537: modify the uploading method and dialog. now it can upload files both to ftp server and webdav server. http://bugzilla.mozilla.org/attachment.cgi?id=145537&action=edit ...

superreview requested: [Bug 24867] UI for FTP upload not implemented : [Attachment 145537] modify the uploading method and dialog. now it can upload files both to ftp server and webdav server. #2
ZF.Dang <dantifer.dang@sun.com> has asked Darin Fisher (IBM) <darin@meer.net> for superreview: Bug 24867: UI for FTP upload not implemented http://bugzilla.mozilla.org/show_bug.cgi?id=24867 Attachment 145537: modify the uploading method and dialog. now it can upload files both to ftp server and webdav server. http://bugzilla.mozilla.org/attachment.cgi?id=145537&action=edit ------- Additional Comments from ZF.Dang <dantifer.dang@sun.com> Darin, please take time to have a look. ...

Upload multiple files to the server without using File Upload
I want to upload multiple files to the server without using input type file (File Upload). Is there a way to do this. What I want to do is retrieve multiple file paths (paths are displayed in a user control like text boxes) and upload those files to the server as a bunch. I tried to set the value of the File Upload cotrol (using javascript) but it was not succeed since attributes of the File Upload are readonly. (document.getElementById("fileUploadValue").value = "C:\Test.txt") Is there a way to override the values in File Upload control or is there a way to up...

How much size of file can be uploaded with file upload control
How much size of file can be uploaded with file upload control? By default its 4mb but it can be chaged through web config settingsAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved. For a detailed explanation on your query have a look into this article http://msdn2.microsoft.com/en-us/library/e1f13641(vs.71).aspxAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point...

Web resources about - When I upload a text file from client to server using stream, how can I guarantee that the uploaded text file can be displayed correctly? - asp.net.web-dev-2005-express

STUDY COUNTERPOINT: Facebook Political Ads Effective When Used Correctly
Not so fast! When used properly, political ads on Facebook are useful, says one public-affairs strategist in response to a study by a pair of ...

invest correctly (@investcorrectly) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here invest correctly @ investcorrectly ...

Speak and Write Correctly on the App Store on iTunes
Get Speak and Write Correctly on the App Store. See screenshots and ratings, and read customer reviews.

Spell Dwyane Wade Correctly and Win $100 - YouTube
Dwyane Wade from the Miami Heat is the athlete that has the most commonly misspelled name. So we thought we'd turn that into a game. We went ...

How To Correctly Use Sex Toys - CityKat
Forget about the what - sex toys are all about the how.

Breathing Correctly
The most natural physiological function can also be one of the hardest to master.

Clark chat must be done correctly: AFL CEO
AFL boss Gillon McLachlan hopes the discussion around Mitch Clark's mooted comeback and potential departure from the Demons is 'done the right ...

Richard Branson offers unlimited vacation days (you read that correctly)
Note: The CBC does not necessarily endorse any of the views posted. By submitting your comments, you acknowledge that CBC has the right to reproduce, ...

The Westboro Baptist Church Just Can't Hate Ireland Correctly
The church has been hating for so long, it's like they've forgotten how to do it!

Park urges Japanese leaders to perceive history correctly
Park urges Japanese leaders to perceive history correctly People's Daily Online Global TimesChinadaily.com.cn Ecns.cn Show ChinaChina Human ...

Resources last updated: 11/24/2015 8:31:26 AM