Click here to Skip to main content
15,884,176 members
Articles / Web Development / ASP.NET

Searcharoo 2007 (Medium Trust and Office 2007 indexing)

Rate me:
Please Sign up or sign in to vote.
4.95/5 (11 votes)
28 Apr 2007CPOL10 min read 203.9K   849   42  
Remove Binary Serialization to solve Medium Trust problem; index OpenXML document formats in ASP.NET/C# free search engine
using System;
using System.IO;
using System.Runtime.Serialization;

namespace Searcharoo.Common
{
    /// <summary>
    /// Required by Binary Deserializer
    /// </summary>
    /// <remarks>
    /// .NET XML and SOAP Serialization Samples, Tips (goxman)
    /// http://www.codeproject.com/soap/Serialization_Samples.asp
    /// 
    /// It's a long story, but basically if you DON'T provide this information
    /// the deserializer gets very confused if the code is recompiled and therefore
    /// has a different 'Type(version)'. See the Catalog.Save() method for it's use.
    /// </remarks>
    public class CatalogBinder : SerializationBinder
    {
        public override Type BindToType(string assemblyName, string typeName)
        {
            // get the 'fully qualified (ie inc namespace) type name' into an array
            string[] typeInfo = typeName.Split('.');
            // because the last item is the class name, which we're going to 'look for'
            // in *this* namespace/assembly
            string className = typeInfo[typeInfo.Length - 1];
            if (className.Equals("Catalog"))
            {
                return typeof(Catalog);
            }
            else if (className.Equals("Word"))
            {
                return typeof(Word);
            }
            if (className.Equals("File"))
            {
                return typeof(File);
            }
            else
            {	// pass back exactly what was passed in!
                return Type.GetType(string.Format("{0}, {1}", typeName, assemblyName));
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
-- ooo ---
www.conceptdevelopment.net
conceptdev.blogspot.com
www.searcharoo.net
www.recipenow.net
www.racereplay.net
www.silverlightearth.com

Comments and Discussions