|
Hi,
in my project i use .Net 2.0 Xml serialization, ie something like that :
<br />
XmlSerializer xmls = new XmlSerializer(typeof(Class1));<br />
StreamWriter sw = new StreamWriter(path, false, Encoding.UTF8);<br />
xmls.Serialize(sw, c1);<br />
sw.Close();<br />
It works perfectly, but i need to implement a zip compression after the xml serialization. So i decided to create an XmlZipSerializer, which implements Serialize and Deserialize methods, but with Gzip compression. So i did something like this :
<br />
public class XmlGZipSerializer : XmlSerializer<br />
{<br />
public new void Serialize(Stream s, object o)<br />
{<br />
GZipStream gzs = new GZipStream(s, CompressionMode.Compress);<br />
StreamWriter first = new StreamWriter(gzs, Encoding.UTF8);<br />
base.Serialize(first, o);<br />
}<br />
public new object Deserialize(Stream s)<br />
{<br />
GZipStream gzs = new GZipStream(s, CompressionMode.Decompress);<br />
StreamReader second = new StreamReader(gzs, Encoding.UTF8);<br />
object o = base.Deserialize(second);<br />
return o;<br />
}<br />
...<br />
}<br />
And use it like this :
<br />
XmlGZipSerializer xmls = new XmlGZipSerializer(typeof(Class1));<br />
using (StreamWriter sw = new StreamWriter(path+".gz", false))<br />
{<br />
xmls.Serialize(sw, c1);<br />
}<br />
But there's a problem (cause if there wasn't i wouldn't have posted ) :
when doing this i get a problem when unzipping (manually with winzip or when deserializing), saying that the XML document is not well formed. Example :
<br />
<Class1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Valeur="132" Nom="test" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t" 5t"<br />
instead of :
<br />
<Class1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Valeur="132" Nom="test" /><br />
But if in the Serialize method i add 'gzs.Close()' after 'base.Serialize(first, o);', the document is well formed. But i can't use this solution with 'using', cause when getting out of the using block i get an exception like : cant close a file already closed.
The thing is i really need to use using blocks in my project, plus closing the stream in the serialize method is not "good".
I tried to use the Flush() methods on my streams but no way, i can't get a well formed xml document when unzipping.
If anyone knows how i could get out of this mess, i would be grateful !
|
|
|
|
|
What will be the syntax for writing a file in C# in which i can write some functions (I want to use these functions in multiple classes). The file must not be a class and i can able to access functions in that file by using syntax like:
namespace.functionName();
I don't want to create any instance of that file (unlike a class). So is there any way to do so? or i am going to some wrong direction?
sAqIb
|
|
|
|
|
public class Utils
{
public static SomeFunc1() { ... }
public static SomeFunc2() { ... }
}
You can call the methods like Utils.SomeFunc1() , no instance is required, because the functions are static . In .NET 2.0 you can also make the class static: public static class Utils
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
thanks. But can we do so without declaring functions static??? is there any possible solution for it?
sAqIb
|
|
|
|
|
you cannot call a function on an object if it is not instantiated. the only way is to make that function static.
regards,
maurice
|
|
|
|
|
hi all
i was trying to download some images using the following code. it was working perfectly before but recently it strted throwing an exception (webclient exception )
System.Net.WebClient wb=new System.Net.WebClient();
wb.DownloadFile(htmladdress,filepath);
Can anyone suggest an idea to overcome??
is it due to some problem in my net connection??
Thanks
|
|
|
|
|
|
I created project , In OpenFileDialog windows under "My computer" Drives are not getting displayed. I checked the system policies everything is fine. What are the different possibilities where i can check why "My Computer" trees is not displaying Drives. (Is there something related to CAS)?
BSK
New Bee
|
|
|
|
|
HI,
Iam new to c# Can anyone help me insolving this problem when i try to give "/n" the display show one small box insted of going to below line
Thank you,
Regards
Praveen
|
|
|
|
|
string line = "This is new \nline";
result:
This is new
line
|
|
|
|
|
It's \r\n, but you should use Environment.NewLine instead.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
you may use '\r' '\n' instead of using \n. This will definitely work
sAqIb
|
|
|
|
|
Iam overriding string to BSTR so /n/r and Environment.NewLine gives again Boxes and no new line.
|
|
|
|
|
isn't newline cairrage return something like 0A 0D or something? You could try adding '/0A', '/0D' to your character array.
It's a wild guess though...
|
|
|
|
|
Hi,
try to use
'\r\n'
Hope this works.
Nitin...
|
|
|
|
|
Hy,
How to use ParseExact with date in this format 20060918T084735Z or 20060918T104723+0200.
Thx
|
|
|
|
|
|
Hi Dear Respected Programmers
kindly help me, i am working in Form2 and i want to use Combobox1 from Form1.
please let me know, How do I work?
|
|
|
|
|
set combobox (in form1) as public (look at combobox property default it is private adn us set it public)
|
|
|
|
|
just change the property of the combobox from private to public, it will be accessible in form2.
sAqIb
|
|
|
|
|
Hi everybody.
as we all know C#, like java, is a reference based language.
so my question is how can I build an array that all of its cells are one after another in the memory? for instace, if I write a B-Tree in c# (or java for that matter), how can one do that?
Thanks
|
|
|
|
|
Green Fuze wrote: as we all know C#, like java, is a reference based language.
Except for value types. e.g. DateTime
|
|
|
|
|
Arrays *are* contiguous in C# (or even Java, for that matter). The fact that they are reference types doesn't mean a linked list like implementation.
|
|
|
|
|
I understand it is an array in the memory (although it is reference, and not a linked list), what I wanted to know how can I "disable" this reference, and create 2 objects in the memory, one after another.
|
|
|
|
|
Try working with pointers in unsafe { } blocks. That gives you the functionality as it is implemented in C++
WM.
What about weapons of mass-construction?
|
|
|
|