Portofolio: GetFreeWallpapers.net

Project description:

When trying to find a way to get my hosting expenses covered I started a Wallpaper-site (pretty lame, but still). At this moment I was playing with Linq and wanted to do some with Linq to Objects. At this moment the site creates his own navigation and image view with Linq to Object based on the file-system.

Used technologies:

  • Asp.Net 3.5 
  • Linq to Objects
  • Asp.Net Cache

Rabobank starterscommunity live

This week we launched the Rabostarterscommunity. This community is build with Telligent Community Server 2008 and SiteCore 5.

For reporting we uses Harvest reporting service and Google Analytics. 

One thing I learned was that the support of Telligent is not good and also the first releases of CS2008 was buggy, some parts didn’t work at all!!! And don’t even get me started about Telligent Harvest Reporting (Just don’t use it).

If you need to start a community be sure to check if you really need community server! If you only need a forum use: Yetanotherforum.

Microsoft SQL Server Database Publishing Wizard 1.1

When I was trying to publish a database to my shared hosting provider I encountered some problems with backup and restoring my database. To restore a database on my provider I needed a full Sql script (schema and data).

After a few attempts with SQL comparer and Management studio I found a link to ‘Microsoft SQL Server Database Publishing Wizard 1.1’. The Publising Wizard does complete backups to SQL script (including data).

When I tried running the Publishing Wizard on my Vista workstation it failed with the following error:
Could not load file or assembly 'Microsoft.SqlServer.BatchParser, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I fixed this error by installing the ‘Feature Pack for Microsoft SQL Server 2005 – November 2005’.

The Publishing Wizard a great tool!

 

 

Linq to Sql: Change connectionstring to load from Web.config

Update 20 may 2009: New easy sollution

Set the Connection -> Application Settings property True. This will generate a connection string in your app.config.

 

Copy this connection string to your web.config and your all set!

 

================================================================= 

Old post: 

If you want to use your connectionstring from the web.config with Linq to Sql (dbml) you have to add the following partial class to your project:

[code:c#]

namespace Your.Namespace
{
  partial class yourDataContext
  {
    partial void OnCreated()
    {
       ConnectionStringSettings s = ConfigurationManager.ConnectionStrings["YourConnectionString"];
       if (s != null)
         Connection.ConnectionString = s.ConnectionString;
    }
  }
}

[/code]

Don't forget to change the Your.Namespace, yourDataContext and YourConnectionString to fit your project.

Hope this helps.

Bitmap Extension Methods; for Resize, Crop and save

For Bitmap manipulation I wrote three extension methods. With this method you can resize, crop and save (as jpg) your image.

 

Resize Method

[code:c#]

public static Bitmap resizeImage(this Bitmap input, Size size)

{

int sourceWidth = input.Width;

int sourceHeight = input.Height;

float nPercent = 0;

float nPercentW = 0;

float nPercentH = 0;

nPercentW = ((float)size.Width / (float)sourceWidth);nPercentH = ((float)size.Height / (float)sourceHeight);

if (nPercentH < nPercentW)

nPercent = nPercentH;

else

nPercent = nPercentW;

int destWidth = (int)(sourceWidth * nPercent);

int destHeight = (int)(sourceHeight * nPercent);

Bitmap b = new Bitmap(destWidth, destHeight);

Graphics g = Graphics.FromImage(b);g.InterpolationMode = InterpolationMode.HighQualityBicubic;

g.DrawImage(input, 0, 0, destWidth, destHeight);

g.Dispose();

return b;

}

[/code]

 

Crop Method

[code:c#]

public static Bitmap cropImage(this Bitmap input, Rectangle cropArea)

{

Bitmap bmpImage = new Bitmap(input);Bitmap bmpCrop = bmpImage.Clone(cropArea, input.PixelFormat);

return (System.Drawing.Bitmap)(bmpCrop);

}

[/Code]

 

Safe Method

[Code:c#]

public static void saveJpeg(this Bitmap img, string path, long quality)

{

// Encoder parameter for image quality

EncoderParameter qualityParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)quality);

// Jpeg image codec

ImageCodecInfo jpegCodec = getEncoderInfo("image/jpeg"); if (jpegCodec == null)

return;

EncoderParameters encoderParams = new EncoderParameters(1);

encoderParams.Param[0] = qualityParam;

img.Save(path, jpegCodec, encoderParams);

}

public static ImageCodecInfo getEncoderInfo(string mimeType)

{

// Get image codecs for all image formats

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

// Find the correct image codec

for (int i = 0; i < codecs.Length; i++)

if (codecs[i].MimeType == mimeType)

return codecs[i]; return null;

}

[/Code]

ListView: OnItemDataBound

Get dataItem onItemDataBound (don't forget to replace the bold parts with your objectname):

[code:c#]

protected void MainPostListView_ItemDataBound(object sender, ListViewItemEventArgs e)

{

YourObject item = (YourObject)((ListViewDataItem)e.Item).DataItem;

}

[/code]

 

Findcontrol within the itemtemplate:

[code:c#]

HyperLink hplTitle = (HyperLink)e.Item.FindControl("hyperLink");

[/code]