Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Monday, December 7, 2009

How to generate a transparent GIF image using C#

There is apparently no easy way to generate a transparent GIF image using the .NET framework. Microsoft provided a method in the Bitmap class called MakeTransparent() but it doesn’t work for GIFs, it only seems to work for PNGs.

To create a transparent GIF you need to recreate the color table of the image using Imaging APIs. Unfortunately, this can be pretty slow for an ASP.NET Web application, and it has a lot of overhead, so I needed an alternative.

Solution:

The alternative is to alter the color table directly using the GIF specification. To implement this, I needed to save the non-transparent GIF to a MemoryStream, and then go through the binary data, updating the color table with the new transparency bits.

Friday, January 30, 2009

Remember Me not working for Login in DotNetNuke based website

The "Remember Me" feature of the DotNetNuke Login is implemented by placing an encrypted authentication cookie on the user's machine.

The expiration of this cookie is controlled through the timeout value in the Forms Autentication node the web.config.

< forms name=".DOTNETNUKE" protection="All" timeout="60" cookieless="UseCookies" />

The default setting is 60 minutes, so it can't remember anyone for very long (I call it goldfish mode).

To extend the time your users are remembered make the timeout value larger.

Wednesday, October 29, 2008

Нow to dynamically change query for ListView linked to LinqDataSource?

In order to dynamically change query for ListView linked to LinqDataSource you have to handle OnSelecting event for LinqDataSource. .

For example:


protected void dsMates_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
if (Request.Params["classMateId"] != null)
{
int mateId;
if (int.TryParse(Request.Params["classMateId"], out mateId))
{
using (DataClassesPrivateMsgDataContext db = new DataClassesPrivateMsgDataContext())
{
e.Result = db.Classmates.Where(mate => mate.Id == mateId).FirstOrDefault();
}
}
}
}

How does it works you can see here: 11-A

Wednesday, October 22, 2008

Code formatter for C#, JavaScript, HTML, ASP.NET for your blog

When posting posts to my blog often need to insert some code saples into the text. It's good to show well formatted code for readers.

If found good free online tool for my purposes:

www.manoli.net/csharpformat/format.aspx

This tool allows you to format your C#, VB, HTML, XML, T-SQL or MSH (code name Monad) code for publishing on a web site or in a blog.

All welcome!