1. Export of asp.net:
<pre name= "code" class= "CSharp" >stringbuilder DATA = new StringBuilder ("");
Response.Clear ();
Response.ContentType = "Text/plain; Charset=shift_jis ";
Response.AddHeader ("Content-disposition", "attachment; Filename= "+ filename +". csv ");
... Obtain data data from DB
. Append (...); Write data to the Data,csv file to split the
Response.Write (data. ToString ());
Response.End ();
Export of 2.WinForm:
...//Get the Save path ...
//Get data from db ...
//with 1, will be "," split the StringBuilder
StreamWriter sw = new StreamWriter ( Exportpath, False, Encoding.GetEncoding ("Shift_JIS"));
Sw. Write (Stringdata.tostring ());
Import of 3.asp.net:
HtmlInputFile txthtmlinputfile = txtfile; Txtfile is the document obtained in the input control in the picture
System.IO.Stream instream = txtHtmlInputFile.PostedFile.InputStream;
DataStream read
byte[] mstreambackup = new Byte[instream.length];
Instream.read (mstreambackup, 0, Int.) Parse (InStream.Length.ToString ()));
The stream
MemoryStream chkstream = new MemoryStream (mstreambackup) used for check;
System.Text.Encoding enc = System.Text.Encoding.Default;
TextFieldParser parser = new TextFieldParser (Chkstream, enc);
Parser. TextFieldType = fieldtype.delimited;
Parser. Setdelimitens (",");
Parser. Trimwhitespace = false;
while (!parser. EndOfData) {
String strorgtext = parser. ReadFields (); Read one row
string[] Strarytext = new String[strorgtext.length];
int i=0;
foreach (String field in Strorgtext) {
strargtext[i] = field;
i++;
}
... Perform various check
... Insert data into DB
}
parser. Close ();
parser = null;
4.WinForm Import:
private sctteam[] impteamary;//Save with Import data Private struct sctteam{public String itema;
//b ...//c}//impteamary write CSV data//Use OpenFileDialog to get csv file String strFileName = openfiledialog1.filename;
StreamReader sr = new StreamReader (strFileName, System.Text.EncodingDefault); String StrText = Sr. ReadToEnd (); Read the last If (strtext.length <= 0 | | | strtext.substring (0, 1)! "\") {...//Read failed message} Sr.
Close (); Strtext.replace ("R", "");
Delete line Wrap string[] strtextary = strtext.split (' \ n ');
if (Strtextary.length < 1) {...//read failure message}//definition and memory Impteamary = new Sctteam[strtextary.length]; for (int i=0; i<strtextary.length; i++) {Impteamary[i] = new Sctteam ();//Ensure memory}//Get data int j=0; The data array index for (int ii=0; ii<=strtextary.length-1; ii++) {if (strtextary[ii). ToString (). Trim ().
Length = = 0) continue; Each project obtains string[] Straryfield = Strtextary[ii].
Split (', '); Impteamary[j].itema = straryfield[0]. ToString ().
Replace ("\", "");
...//b.//c j + +; }