|
Ummm... What?
Are you asking which is better? Neither! Each individual object has its own requirements for calling .Dispose . Such as all the GDI objects (Graphics, Bitmap, Image, Icon, ...) all require you to call their .Dispose methods when you're done with them. Not doing so will result in OutOfMemory Exceptions sooner or later.
Pretty much, the rule of thumb is if the object requires an underlying system handle or other unmanaged resource, you MUST call .Dispose on that object when you're done with it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i am a beginner to .Net Framework. I want to know some of the website to visit
sowjanya kumar
|
|
|
|
|
|
There's hundred of them! All you need to do is Google for ".NET Framework tutorials"...
But The Code Project is a good place to start!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: There's hundred of them! All you need to do is Google for ".NET Framework tutorials"...
But The Code Project is a good place to start!
Dave is right. Myself, I have this site bookmarked, heck, even as the default startup page for that matter, and numerous other sites that pertain to anything for .Net bookmarked. This site is a definite starting point.
Happy .Net programming,
Paul
|
|
|
|
|
Other than this site:
* msdn.microsoft.com/[^] - The Microsoft Developers Network is the premium resource from MS.
* DotNetRocks[^] - Podcasts that teach you about various aspects of .NET
* dnrTV[^] - Video tutorial/interviews from DotNetRocks team.
I recommend listening to DotNetRocks when you are driving or doing your daily commute. It is an excellent source of information during an otherwise dead time.
ColinMackay.net
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucius
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
|
|
|
|
|
This[^] is a good source of tutorials. And of course, right here at CodeProject!
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Greetings all.
I've made an e-mail module for a client where they can send e-mails with attachments to their clients.
To minimize against faulty entered e-mails I've made some functionality which removes e-mail adresses which are rejected by the server (error 550).
However, then I found something strange.
When ever I try to send an e-mail, the attachments get cleared, meaning that my recovery functionality will remove 550-faulty addresses and resend the e-mail but this time withouth the attachment.
I've found that if I send the mail successfully - the attachment is also removed after the send.
I'm using a wrapper-class around System.Web.Mail namespace and using smtp.mail.send(mailobject) to send the e-mail. There is not much to this wrapper class except some functionality to check whether recipient(s) and sender have been added.
Attachments get added by: "myMailObject.Attachments.Add(New MailAttachment(fileName))"
Now - to make the short story longer ....
Is this "clearing" of attachments inherit .net behaviour? Or would the problem lay elsewhere?
Regards
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
Never tried it, so I never noticed it. But, a workaround is pretty easy. Keep track of the email attachment filenames yourself and don't rely on the MailMessage object to do it for you. If you need to put the attachments back, you already have your own list to refer to so you can do it again.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Yep - it is no problem doing a workaround, I did that myself along the same line you mention because my attachments are already persisted in a database.
I was just wondering if it was .net behaviour (or messed up code I'm using) and possible if anybody knew something about why
Thanks for the reply.
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
No idea. I don't see anything in the System.Web.Mail classes that would clear out the Attachments collection. The code never deletes anything from the collection and the collection is never refreshed from the contents of the underlying COM object either.
From the Framework's perspective, if the collection is being cleared out, you're doing it somehow.
But I find that hard to believe.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks for the feedback.
I didn't read anything about this in the framework description either, but I just couldn't read out of the wrapper code that it would do something like this.
I'll try to debug the wrapper intensely and test it, to see if I can find this disparity.
---------------------------
127.0.0.1 - Sweet 127.0.0.1
|
|
|
|
|
Basicly I want to be able to compress a String using System.IO.Compression to another String and be able to decompress it later.
I want to use this for compressing XML (and other string values) into a String variable which I store elsewhere. It MUST be compressed to a String - no binary data.
Also, I do not want to save the XML to a file and compress/decompress from there; compressing/decompressing must be in-memory only.
Any advice or sample code (VB.NET or C#) ?
Thanks in advance
|
|
|
|
|
You do realize that the Compression class only outputs binary data? Outputs to any stream by the way, even a MemoryStream object. You can find an example here[^].
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
"You do realize that the Compression class only outputs binary data?"
Yes, but this can be converted (encoded) to/from a String with .NET (can't remember the class name right now).
Also, I'm NOT looking for something to compress a stream...
Anybody else, please ?
|
|
|
|
|
MrBean wrote: Also, I'm NOT looking for something to compress a stream...
Actually, you are! Consider the String as just a stream of characters in memory. See this[^] for more information.
MrBean wrote: Yes, but this can be converted (encoded) to/from a String with .NET (can't remember the class name right now).
You could probably do what you want with a StringBuilder[^] object.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Dave Kreskowiak wrote: Actually, you are! Consider the String as just a stream of characters in memory. See this[^] for more information.
Yes, you are right - but I'm looking for some code which shows me how to do it in more detail
I got the compression code to work just fine, but can't seem to decompress it.
Here's the compression code which seems to work :
Public Function CompressString(ByVal strInput As String) As String
Dim buffer() As Byte = Encoding.UTF8.GetBytes(strInput)
Dim memoryBuffer As New MemoryStream()
Dim compressedZipStream As New GZipStream(memoryBuffer, CompressionMode.Compress, False)
compressedZipStream.Write(buffer, 0, buffer.Length)
compressedZipStream.Close()
Return Convert.ToBase64String(memoryBuffer.GetBuffer)
End Function
Dave Kreskowiak wrote: You could probably do what you want with a StringBuilder[^] object.
Ok, but Convert.ToBase64String seems to work also
|
|
|
|
|
OK. That seems to work. Now how about the decompression code? It should be doing the exact same thing in reverse...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well... can't get it to work
Below is the code that I'm currently "fiddling" with.
The CompressString function has been revised and seems to work correctly now. But the Decompress function method somehow still doesn't work.
ZipStream.Read simply doesn't decompress the data in the memoryStream and returns 0 ??
Public Function CompressString(ByVal strInput As String) As String
Dim bufIn() As Byte = Encoding.UTF8.GetBytes(strInput)
Dim bufIn() As Byte = Encoding.UTF8.GetBytes(strInput)
Dim ms As New MemoryStream()
Dim ZipStream As New GZipStream(ms, CompressionMode.Compress, False)
ZipStream.Write(bufIn, 0, bufIn.Length)
Dim bufOut() As Byte = ms.GetBuffer
ZipStream.Close()
Return Convert.ToBase64String(bufOut)
End Function
Public Function DeCompressString(ByVal strInput As String) As String
Dim bufIn() As Byte = Convert.FromBase64String(strInput)
Dim ms As New MemoryStream()
ms.Write(bufIn, 0, bufIn.Length) ' Compressed data
ms.Position = 0
Dim ZipStream As New GZipStream(ms, CompressionMode.Decompress)
Dim bufOut(30000) As Byte ' Predefined buffer-size just for test purposes!!
Dim nRead As Integer
nRead = ZipStream.Read(bufOut, 0, bufOut.Length) ' Returns 0 ????
ZipStream.Close()
Return Convert.ToString(bufOut) ' never mind this... WIP
End Function
|
|
|
|
|
This code should do the trick:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
namespace CompressDecompress
{
class Program
{
static void Main(string[] args)
{
string LstrTest = "This is a test";
string LstrOutput;
LstrOutput = CompressString(LstrTest);
LstrTest = DeCompressString(LstrOutput);
Console.WriteLine(LstrTest);
}
public static string CompressString(string PstrInput)
{
MemoryStream Lms;
GZipStream LstmZipStream;
byte[] LbytBufIn;
byte[] LbytBufOut;
LbytBufIn = Encoding.UTF8.GetBytes(PstrInput);
Lms = new MemoryStream();
LstmZipStream = new GZipStream(Lms, CompressionMode.Compress, false);
LstmZipStream.Write(LbytBufIn, 0, LbytBufIn.Length);
LbytBufOut = Lms.GetBuffer();
LstmZipStream.Close();
return Convert.ToBase64String(LbytBufOut);
}
public static string DeCompressString(string PstrInput)
{
MemoryStream Lms;
GZipStream LstmZipStream;
UTF8Encoding Lutf;
byte[] LbytBufIn;
byte[] LbytBufOut;
int LintRead;
LbytBufIn = Convert.FromBase64String(PstrInput);
Lms = new MemoryStream();
Lms.Write(LbytBufIn, 0 , LbytBufIn.Length);
Lms.Position = 0;
LbytBufOut = new byte[LbytBufIn.Length];
LstmZipStream = new GZipStream(Lms, CompressionMode.Decompress);
LintRead = LstmZipStream.Read(LbytBufOut, 0, LbytBufOut.Length);
LstmZipStream.Close();
Lutf = new UTF8Encoding();
return Lutf.GetString(LbytBufOut, 0 , LintRead);
}
}
}
|
|
|
|
|
Thanks for the code... I'll try it later
So far I have solved my problems by using a 3rd party component (Xceed) which was part of a suite we had allready purchased.
It workes perfectly, is very easy to use and is apparently more efficient
|
|
|
|
|
hi all,
i am new to vb.net. how can we add Microsoft common dialog control 6.0(sp3) to vb.net project
raj
|
|
|
|
|
Why would you want to when the dialogs are already in the .NET Framework?
OpenFileDialog, SaveFileDialog, ColorDialog, FolderBrowserDialog, FontDialog, PageSetupDialog, PrintDialog, ...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I create a document by using a class and inheriting from PrintDocument. On the PrintPage event i keep adding new pages etc. This part is succesfull so far because i then view the document in the print preview dialog all 34 pages.
However when i attempt to print the document by clicking on the print button of the dialog control ONLY THE LAST PAGE GETS SENT to the printer.
I have played around with printersettings option but to no avail.
If you can think of why i have this problem please let me know,
i would be very grateful if you could help.
Thanks.
Mo.
|
|
|
|
|
Is there any way to get a parent control to accept messages before a child control does? For instance, I have a richtextbox inside of a control that is inside of my current control that seems to be grabbing my OnDrag... messages. I want any of the OnDrag... functions to be handled by my control first and then passed to the child controls to be handled by them. Heck, it would even be good if the child control handled it first and then it percolated outwards to my parent control. That is not happening, however. What is happening is that my dragdrop is being prevented by the inner child control, which ruins the functionality of my outermost parent control.
Is what I'm trying to do possible?
|
|
|
|