I have an ASP.NET page that shows stuff (data in tables), does stuff (modifies data) and sometimes sends email about these. It used to work without problems, but recently something broke with the encoding.
The site uses hungarian characters like 'Á', 'Ú' or 'Ő', etc, but this was never a problem before, it displayed them correctly. But recently the emails it sends arrive looking like this:
Sérült tétel státusz változás
Instead of looking like this, as it should:
Sérült tétel státusz változás
The problem is not only with the emails, but sometimes with label texts as well. For example, using this:
Label.Text = "Saját jegyzőkönyveim"
Results in the label showing as:
Saját jegyzőkönyveim
But this only seems to be an issue if label text is set in code-behind. If the label text is set in the .aspx file, then it displays fine. The text content of the emails are also set in the code behind, so I believe the issue must be with the encoding with the .cs file. A while ago I even remember Visual Studio complaining something about the encoding of the files when I saved them once, but I don't remember what it was complaining about. But anyway, I believe it somehow set it to a different encoding or something. It's probably related to a single file, as our other pages still send emails correctly, even though they run under the same web.config, etc.
So what might be the issue? Trying Save As and change encoding there it's already set at UTF-8, so where else might it be changed that causes this? Any help is appreciated, thanks in advance!
Case solved. Turns out the .cs file was encoded in "UTF-8 without signature", while it was supposed to be "UTF-8 with signature".
Related
This is driving me crazy, because I thought I had the runat=server stuff totally figured out.
I have an asp:Literal control in my markup (it's in a masterpage, but that doesn't matter, right?)
In MyMaster.Master:
<asp:Literal ID="myLiteral" runat="server" Text="Some Text"></asp:Literal>
Then, in the codebehind (MyMaster.Master.cs), I have:
myLiteral.Text = "Some different text";
No matter what I try, I get
The name 'myLiteral' does not exist in the current context
I've tried cleaning and rebuilding my whole solution, but it doesn't make any difference.
What am I doing wrong?
Edit: To clarify, I'm trying to change the text of the Literal control in the codebehind of the master page, not a content page. Specifically, I'm doing this in the Page_Load method of the master file.
Figured it out! I wish I knew why, but the Masterfile was missing it's corresponding .designer.cs file. I tried several things to get VS to regenerate the designer file, but I finally found the trick in one of the answers to this question.
The trick is to create an empty code file with the correct name (in my case MyMaster.Master.designer.cs. Then open the masterfile (MyMaster.Master) and make some small change to cause VS to resave the file. When that happens, it magically fills in the empty designer file!
So, this problem is solved. However, if anyone knows why a) my designer file disappeared in the first place, and b) if there's any better way of forcing VS to regenerate the designer files if they happen to disappear, that would fantastic.
that is some problem of VS, i have witness such issues in VS 2010 when the controls were not forming. Whenever such things happens i try the following things -
1. Cleaning and rebuilding solution.
2. Dragging and dropping the contacts from toolbox which is not creating.
3. Restarting computer.
This thing happens only sometimes. I would recommend you to use VS 2013 as it is mostly bug free(if not 100%).
Thanks
I have a Win Form application that does some boring accounting stuff and then sends it's data to some lucky recipients. I am using the Outlook 12.0 Interop objects and my applications environment ranges from office 2003 on XP to office 2007 on Win 7.
My issue lies with sending the corporate signature with the sent emails.
It contains two images and I would like to embed these images so they appear to be part of the body (assuming the receiving mail client supports that).
I have tried a few different methods of accomplishing this; but still no luck!
I have tried:
Extracting the html data from the signatures folder, changing the
html img tags src attribute to include 'file///'. This causes Outlook
to replace the 'file///' with 'CID' and I assumed it would also embed
the image... we should never assume :|. This is the method I found
worked best for getting the rest of the signature.
(After creating a new MailItem) - Grabbing the HTMLBody of the MailItem
and extracting the relevant part including the signature... This
didnt work due to the new MailItem object being very inconsistent
with it's signature. By that I mean sometimes the new item would
include the signature and sometimes it wouldn't! :s I cannot figure out why it is not always there, no other part of my code has changed!
I read on another post here about the GetInspector property... Apparently just calling this will do 'Some stuff' and the signature will magically appear in your mail item... NO!
Things I can't do:
I cannot (as much as i would like to) shove the images online
somewhere and point to them in the emails html.
I cannot use SMTP(It has to be through Outlook... sigh).
I am thinking that the best way seems to be my original method of messing about with the CID, but I do not really know much about what Outlook is doing in the background so I am having trouble figuring out what else I need to do to get the images sent along with the email.
Hoping someone out there has some idea about what I am doing wrong or what else I could try.
Please let me know if code would be helpful and I will post, (Most of the code tried is from this site... I just cannot find the links again and am trying to avoid making this question tooooo long).
Many thanks
This is not the most efficient or flexible solution you can use, but probably the most robust and portable. You can convert your image bitmap into plain HTML and embed that HTML in your e-mail signature.
The conversion is quite simple, you can use the utility I wrote (open source) here.
I have two separate C# ASP.NET programs running on the same server. Each of them uses the Richtextbox control in their respective business layer dll's to strip RTF formatting from text stored in the database as such.
var rtf = new RichTextBox {Rtf = itemWeb.RTF_DESCRIPTION};
item.WebDescription = rtf.Text;
The problem is, when both programs execute it often happens where this line fails(on both programs) with the following error.
[Win32Exception (0x80004005): Error creating window handle.]
These programs do not share any code or dll's whatsoever. The only thing in common is the technique used to strip the formatting and the fact that they are on the same server.
Is there a known issue using the Richtextbox this way? I didn't write the code, but it seems non-standard to use a UI element in a dll, even though this is the common solution when searching for how to strip formatting.
Ideally, I would find a solution without using the Richtextbox. I found one using the regex that comes close, but does not guarantee that 100% of the formatting will be stripped. Any explanations as to why this is happening or any workarounds will be appreciated.
Thanks!
I started getting the same error recently with a method in a static class that converts from RTF to Text.
I tracked it down to the RichTextBox not being properly disposed (or possibily quickly enough) even though the context the RichTextBox was in the method (not global).
If your code doesn't get executed a lot, this might not be the same problem.
It can be reproduced by coding a test care that run through the conversion 30,000+ times. Implementing a using clause solved the problem.
using (System.Windows.Forms.RichTextBox rtBox = new System.Windows.Forms.RichTextBox())
{
rtBox.Rtf = str;
str = rtBox.Text; // convert the RTF to plain text.
}
This worked but it is pretty slow. It would be nice to be able to do this without having to create a control, but that's Microsoft's official advice for RTF conversion.
I seek a little bit of advice...
I have an WPF C# program with an XML resource file in which I have text for some buttons, like a language file (let's call it language.xml), and 2 xml more, for example english.xml and spanish.xml.
I have the XmlDataProvider pointing to language.xml
At startup I seek in a database which language has the user in his/her configuration, and I overwrite language.xml with the content in english.xml or spanish.xml
Sometimes the program loads right, but most of the time it loads the wrong data, although you look in the language.xml and the data is right.
(When I say wrong data I mean loading the program and entering with one user with a language set, closing, and entering with another one with other language...).
It's a little bit confusing, but I hope someone have tried something like this...
Thank you in advance. :)
May be problem is in synchronization.
As example, your program begin request to database, and starts UI. XmlDataProvider is created with old xml source, then (on service response) language.xml is rewritten with new value.
More details or code parts will help to understand your situation.
Ok, got it. I had to reload the XmlDataProvider in the Loaded method.
In addition, seeing that I had to reload the XmlDataProvider itself, I set it to point directly to the correct .xml file. :)
Thank you for your answers!
You need to debug and see exactly where things get initialized ?
It would be quite simpler to have just set the language and point to the correct xml file rather than your language.xml file.You already have two language files so why do do need additional operations ....
Try to simplify and then see if you still get the proplem.
In C#, I'm sending a mail with an activation link to users after they have registered. However, the link is split over two lines in the mail and thus doesn't work.
I've checked in Visual Studio and the string containing the link looks fine.
I've also tried:
strMessage.Replace("\r", "");
strMessage.Replace("\n", "");
but without success.
Do you have any ideas on how to solve this? I've googled it for hours and can't find the solution...
Thanks!
/J
Is the link longer than 78 chars? Or is there some other text in front of it?
If so, see if you can make it less than 78 and I don't think it'll wrap it. Otherwise, I seem to remember that this could be sort of fixed in some email applications by changing the encoding, possibly the same might work here since I see that there are various Encoding properties of MailMessage.
If you are sending the message as an HTML email, then you could put a link around the email so that it renders on one line, and then have the actual link in brackets with instructions on how to copy and paste it ensuring it's on one line.
Register here
(if the above does not appear in a link, copy the following link into your
browser ensuring that it all goes on one line:
http://www.longaddresshere.com/thatkeepswrapping)
I finally managed to solve this annoying problem. It seems like Outlook was the cause of everything, it divided my LONG html string into two lines. My link just happened to be right at the point of the line break. So I added the sufficient number of characters (with the same color as the background) to make my link start on the second line.
Not the best solution, but it worked in this case...