<Form ID = "form1" runat = "server">
<Asp: fileupload id = "fileupload1" runat = "server"/>
<Asp: button id = "button1" runat = "server" text = "button" onclick = "button#click"/>
<Asp: button id = "button2" runat = "server" onclick = "button2_click" text = "button"/>
</Form>
// Code Using system;
Using system. collections;
Using system. configuration;
Using system. Data;
Using system. LINQ;
Using system. Web;
Using system. Web. Security;
Using system. Web. UI;
Using system. Web. UI. htmlcontrols;
Using system. Web. UI. webcontrols;
Using system. IO;
Using system. xml;
Using system. xml. serialization;
Using system. text;
Public partial class pages_pagetest: Page
{
Protected void page_load (Object sender, eventargs E)
{
}
Protected void button#click (Object sender, eventargs E)
{
Stream f_stream = This. fileupload1.postedfile. inputstream;
Binaryreader BR = new binaryreader (f_stream, system. Text. encoding. Default );
Byte [] DATA = new byte [f_stream.length];
BR. Read (data, 0, Data. Length );
Stringbuilder strb = new stringbuilder ();
Strb. append (convert. tobase64string (data ));
Pic pbj = new PIC ();
PBJ. s_pid = strb. tostring ();
PBJ. ID = 3;
Filestream FS = NULL;
Try
{
Xmlserializer xs = new xmlserializer (typeof (PIC ));
FS = new filestream (server. mappath ("~ /A. xml "), filemode. Create, fileaccess. Write );
Xs. serialize (FS, PBJ );
FS. Close ();
}
Catch (exception ex)
{
If (FS! = NULL)
FS. Close ();
Throw new exception ("XML serialization failed! ");
}
}
Protected void button2_click (Object sender, eventargs E)
{
Filestream FS = NULL;
Try
{
Xmlserializer xs = new xmlserializer (typeof (PIC ));
FS = new filestream (server. mappath ("~ /A. xml "), filemode. Open, fileaccess. readwrite );
Pic obj = Xs. deserialize (FS) as PIC;
Byte [] DATA = convert. frombase64string (obj. s_pid );
Response. binarywrite (data );
Response. End ();
FS. Close ();
}
Catch (exception ex)
{
If (FS! = NULL)
FS. Close ();
Throw new exception ("XML serialization failed! ");
}
}
}
Public class PIC
{
Public String s_pid;
Public int ID;
}