Friday, May 22, 2009

Sitecore 6: "If you publish now, the selected version will not be visible on the Web site because it is not in the final workflow step."

In the Content Editor go to the Review tab. Use the workflow section to progress the item through to approval.

Tracking the current GPS position by auto refreshing a KML file

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
  <NetworkLink>
    <name>GPS</name>
    <flyToView>1</flyToView>
    <Url>
      <href>path/to/auto/update/file.kml</href>
      <refreshMode>onInterval</refreshMode>
      <refreshInterval>2</refreshInterval>
    </Url>
  </NetworkLink>
</kml>

Sitecore 6 resources

Google hasn't been very successful in finding relevant information about Sitecore 6. Or perhaps I haven't been searching for the right terms. Still I've found the Security API Cookbook to be really useful for developing custom security providers.

Wednesday, May 13, 2009

Excluding the Exception stack trace from the log4net Layout

The blog post Producing readable log4net output has some good ideas for excluding the Exception StackTrace from LoggingEvents.

In my case I used loggingEvent.GetLoggingEventData(FixFlags.All) to get a copy of the LoggingEventData. I then cleared the ExceptionString in the LoggingEventData and used this to create a new LoggingEvent for use in RenderLoggingEvent.

Tuesday, May 12, 2009

Working with the Google Documents API to download PDF in C#

I got caught up for a bit trying to use Google.GData.Documents.DocumentsFeed and Google.GData.Documents.DocumentEntry to download a Google Document as a PDF. Then I found the Google.Documents namespace and the problem became trivially easy.

using System;
using System.IO;
using System.Net;
using Google.Documents;
using Google.GData.Client;

namespace Google
{
    class Program
    {
        private static string applicationName = "Testing";

        static void Main(string[] args)
        {
            GDataCredentials credentials = new GDataCredentials("username@gmail.com", "password");
            RequestSettings settings = new RequestSettings(applicationName, credentials);
            settings.AutoPaging = true;
            settings.PageSize = 100;
            DocumentsRequest documentsRequest = new DocumentsRequest(settings);
            Feed documentFeed = documentsRequest.GetDocuments();
            foreach (Document document in documentFeed.Entries)
            {
                Document.DownloadType type = Document.DownloadType.pdf;

                Stream downloadStream = documentsRequest.Download(document, type);

                Stream fileSaveStream = new FileStream(string.Format(@"C:\Temp\{0}.pdf", document.Title), FileMode.CreateNew);

                if (fileSaveStream != null)
                {
                    int nBytes = 2048;
                    int count = 0;
                    Byte[] arr = new Byte[nBytes];

                    do
                    {
                        count = downloadStream.Read(arr, 0, nBytes);
                        fileSaveStream.Write(arr, 0, count);

                    } while (count > 0);
                    fileSaveStream.Flush();
                    fileSaveStream.Close();
                }
                downloadStream.Close();
            }

        }
    }
}

Monday, May 11, 2009

Base 64 encoding for a 1x1 px transparent gif

This is how a 1 by 1 pixel transparent gif appears when base 64 encoded.

R0lGODlhAQABAPcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAAABAAEAAAgEAP8FBAA7";
Response.ContentType = "image/gif";
Response.BinaryWrite(System.Convert.FromBase64String(content));
Response.End();

Friday, May 8, 2009

Encrypt the connectionString used by the log4ent AdoNetAppender

When using the log4net (1.2.10) AdoNetAppender I needed to encrypt the connection string as it contained the DB users name and password. I couldn't find an easy way to do this so I ended up reading the connection string from the parent apps web.config. See: Stack Overflow: Encrypt the connectionString used by the log4ent AdoNetAppender