Sharepoint Insight by Namwar Rizvi

Sharepoint Tips, Tricks and inside knowledge from real world experience by Namwar Rizvi

Posts Tagged ‘MOSS’

How to generate a valid SharePoint FileName

Posted by namwar on June 17, 2010

SharePoint imposes several restrictions for the filenames. To get the details of all these restrictions, please check this support article from Microsoft. I have created a utility function to convert a given string to a valid SharePoint filename. This function is valid for SharePoint 2003, 2007 and 2010. Here you go

public string ConvertToValidSharePointFileName(string originalFileName)
            char[] InvalidFilenameCharacters = new[] {'\\', '/', ':', '*', '?', '"', '<', '>', '|', '#', '{', '}', '%', '~','&' };
            string[] InvalidFileNameStrings = new[] { ".files", "_files", 
                "-Dateien", "_fichiers", "_bestanden","_file", 
                "_archivos", "-filer", "_tiedostot", "_pliki", 
                "_soubory","_elemei", "_ficheiros", "_arquivos", 
                "_dosyalar", "_datoteke","_fitxers", "_failid", 
                "_fails", "_bylos", "_fajlovi", "_fitxategiak"};
            string validSharePointFileName = originalFileName;

            //Remove Invalid characters
            validSharePointFileName = validSharePointFileName.Remove(InvalidFilenameCharacters);
            //Remove consecutive periods(..)
            while (validSharePointFileName.Contains(".."))
                validSharePointFileName = validSharePointFileName.Replace("..", ".");

            //Remove reserved words from end
            foreach (string s in InvalidFileNameStrings)
                if (validSharePointFileName.EndsWith(s))
                    if (validSharePointFileName.Length > s.Length)
                        validSharePointFileName = validSharePointFileName.Substring(0, validSharePointFileName.Length - s.Length);

            //Remove period (.) at end
            if (validSharePointFileName.EndsWith("."))
                validSharePointFileName = validSharePointFileName.Remove(validSharePointFileName.Length - 1, 1);

            //Remove period (.) at end
            if (validSharePointFileName.StartsWith("."))
                validSharePointFileName = validSharePointFileName.Remove(0, 1);

            return validSharePointFileName;

Posted in C#, Solutions, SP2010, Tips | Tagged: , , , , | Leave a Comment »

How to solve “Unable to connect publishing custom string handler for output caching”

Posted by namwar on January 11, 2009

If you are getting “Unable to connect publishing custom string handler for output caching” error in your event log then it is because of a custom web service you have installed on your Sharepoint server. Reason for this error is that you have a web part on your portal page which use the custom web service. Now, since Sharepoint uses output caching for the web pages to optimize the rendering experience and fast delivery of unchanged pages therefore, publishing infrastructure of Sharepoint tries to access the web service through your web part and due to any issue in your service, it starts generating this error.

Anyway, cutting a long story short, here is the solution:

Edit the web.config of custom web service (Please do not edit your Sharepoint Web application web.config) and make sure you have following under httpModules node which is located under system.web node. 

            <remove name=PublishingHttpModule />

Posted in Errors, Management | Tagged: , , , , | 7 Comments »

How to check if the file is indexed in SharePoint or not?

Posted by namwar on September 17, 2008

If you want to know whether your file is indexed in Sharepoint Search Services Provider (SSP) or not then there is no way provided directly in the object model of SSP.

Since Sharepoint stores its content on SQL Server therfore, you can run the following TSQL query to find it:

Select * from dbo.MSSAnchorText where Link='<Your File Path>'
Note: Please note you need to replace <Your File Path> by the full path of the your intended file in the above query
Select * from dbo.MSSAnchorText where Link='http://mossdev/Shared%20Documents/UserManual.pdf'

Posted in Object Model, SSP | Tagged: , , , , | Leave a Comment »