Main

.NET Archives

December 14, 2006

Changing the default language in Visual Studio 2005

Instead of under some menu item like "Option" or "Configuration", the place where the default language can be changed is "Tools->Import and Export Settings". And you have to reset the settings in order to get a chance to choose a different language and let it do some configuration magic from scratch. Fortunately, you can backup your previous settings when resetting it. But I am not positive that you can merge your old settings (except the language of course) back to the new settings.

February 7, 2007

Create thumbnails of PowerPoint presentations in C#

It's sometimes useful to generate JPEG thumbnails of office documents programmatically.  With Office object library, it's very convenient to do this in C#.NET.  If it's for a quick and dirty task, an easy way is to convert the office document into a webpage and then use a WebBrowser control to generate the thumbnail.  For a more performance oriented task, customized controls subclassed from the Office classes could be written to dump the bitmaps directly into images.  The following is a sample implementation of the first approach.  Don't forget to add the reference to COM object library "Microsoft PointPoint 12.0 Object Library".

Creating Thumbnails for PowerPoint Presentations
using PowerPoint = Microsoft.Office.Interop.PowerPoint;

private void pptThumbnail(string sourceFile, string targetFile, int thumbW, int thumbH)
{
    // Open the document and convert into HTML pages
    PowerPoint.ApplicationClass oApp = new PowerPoint.ApplicationClass();
    PowerPoint.Presentation oDoc = oApp.Presentations.Open(
        sourceFile,
        Microsoft.Office.Core.MsoTriState.msoTrue, // read only
        Microsoft.Office.Core.MsoTriState.msoTrue, // untitled
        Microsoft.Office.Core.MsoTriState.msoFalse); // with window
    string tmpHtmlFile = System.IO.Path.GetTempFileName() + ".html";
    oApp.Presentations[1].SaveCopyAs(
        tmpHtmlFile,
        PowerPoint.PpSaveAsFileType.ppSaveAsHTML, // format
        Microsoft.Office.Core.MsoTriState.msoTrue); // embed true type font

    // Create the thumbnail from the HTML pages
    Size browserSize = new Size(800, 800);
    WebBrowser browser = new WebBrowser();
    browser.Size = browserSize;
    browser.Navigate(tmpHtmlFile);
    while (WebBrowserReadyState.Complete != browser.ReadyState)
    {
        Application.DoEvents();
    }
    Bitmap bm = new Bitmap(browserSize.Width, browserSize.Height);
    browser.DrawToBitmap(bm,
        new Rectangle(0, 0, browserSize.Width, browserSize.Height));
    Bitmap thumbnail = new Bitmap(thumbW, thumbH);
    Graphics g = Graphics.FromImage(thumbnail);
    g.DrawImage(
        bm,
        new Rectangle(0, 0, thumbnail.Width, thumbnail.Height),
        new Rectangle(0, 0, browserSize.Width, browserSize.Height),
        GraphicsUnit.Pixel);
    thumbnail.Save(targetFile);
}

February 25, 2007

Extract Favorite Websites Collection from Bookmark RSS feeds

Bookmarking a website and bookmarking an article are different usage of the bookmarking tools. You may want to have a clean collection of all your favorite websites and on the other hand you may want to bookmark multiple good articles from the same website. This way your bookmark collection is a mixture of both. This is my little frustration of using sites like http://del.icio.us/. It's great in collect articles and links, but not so great to keep a clean list of my favorite websites. Although I can use a different bookmarking tool (e.g., http://favorites.live.com/, which could sync with IE bookmarks) to collect just sites, it'd be nice if I could keep them in one place. So I developed a custom web control that could be put on your website to display all the websites of a list of http://del.icio.us/ RSS feeds in the order of popularity. Multiple articles of each websites are collapsed into one entry shown for that website, and the number of the articles bookmarked from that site is used as the indicator of the popularity of that site within the RSS feeds. So the more articles of a website that are bookmarked, the more popular the website is. In my example of using this web control, I put my bookmark feeds and the del.icios.us homepage hotlist feeds in so that I will get a list of all the websites either I bookmarked or on the hostlist.

<cc1:BookmarkedWebsites
    id
="WebCustomControl1_1"
    Url
="http://del.icio.us/rss/dbtu/; http://del.icio.us/rss/"
    runat
="server"></cc1:BookmarkedWebsites>

The "Url" property of the control specifies a list of RSS feeds to extract from. The delimiter is ";".

RSS.NET library is used to parse the RSS feed. The website part (domain) of the URL is extracted and used as the collapsing key.

protected override void RenderContents(HtmlTextWriter output)
{
    // Get each individual RSS feed
    char
[] delimiters = { ';' };
    string[] feeds = Url.Split(delimiters);
   
    // Get all websites
    SortedDictionary
<string, int> sites =
        new
SortedDictionary<string, int>();
    foreach (string feedUrl in feeds)
    {
        RssFeed feed = RssFeed.Read(feedUrl);
        foreach (RssChannel channel in feed.Channels)
        {
            foreach (RssItem item in channel.Items)
            {
                string link = item.Link.Scheme + "://" +
                    item.Link.Host;
                if (sites.ContainsKey(link))
                {
                    sites[link]++;
                }
                else
                {
                    sites[link] = 1;
                }
            }
        }
    }

    // Reorder it on the number of occurrence (thus popularity)
    KeyValuePair
<string, int>[] popSites =
        new
KeyValuePair<string,int>[sites.Count];
    sites.CopyTo(popSites, 0);
    Array.Sort(popSites, new SitePopularityComparer());
    foreach (KeyValuePair<string, int> s in popSites)
    {
        output.Write("( " + s.Value + " ) <a href=\"" +
            s.Key + "\">"+ s.Key + "</a><br />");
    }
}

public class SitePopularityComparer : IComparer
{
    int IComparer.Compare(object x, object y)
    {
        return ((KeyValuePair<string, int>)y).Value -
                ((KeyValuePair<string, int>)x).Value;
    }
}

The web control looks like the following:

 

Furthermore, it would be cooler to be able to sync this website list into the browser bookmark so that you can use them as your reading list even more conveniently.

The prototype source code can be downloaded here: MyFavoriteWebSites.zip.

March 1, 2007

Can't set break points in Visual Studio debugger due to symbol loading problems?

When you can't set break points when the debugger is running, it's most likely due to symbols loading related problems.  Instead of smashing your computer, check the following first:
  • Make sure you really setup the symbols.  Tools -> Options -> Debugging ->Symbols.  Add all the paths where expected .pdb files are stored.  Also make sure the permission is set correctly on the folder, especially for remote shared folders.  Use "net use …" command if necessary.
  • In VS2005, Tools -> Options -> Debugging -> General.  Uncheck "Just my code".
  • Make sure the application is running in debug instead of release mode.  Check web.config file for tag <compilation debug="true">, or right click the solution in the solution explorer and choose properties.
  • The timestamp of the .pdb files and their corresponding .dll files are in sync.  The unmatching symbol files are not picked up, because if they are not matching, there could be unexpected harmful running results.
  • Check the Module window (Debug -> Windows -> Modules) and make sure all symbols are loaded when running the debugger.
  • Delete bin and obj folders, restart VS or OS and retry.
  • Delete the project and fetch source tree again and retry.
  • If none of the above helps, go ahead and smash your computer.

About .NET

This page contains an archive of all entries posted to Stanley Yao's Blog in the .NET category. They are listed from oldest to newest.

Industry is the next category.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 3.33