Saturday, November 23, 2013

Special Characters handling for filename in SP List

I was working with one of our client where we have developed some custom forms [Visual Web Part] which were saving the data in the SP List.
 
Problem: After go-live on the support business has reported that for some of the items they were seeing the duplicate entries for the items. After long analysis i have figured out that it is happening because business were trying to attached the files with special characters. when they tried SP was giving the error message but was not sufficient for some of the users and they were creating those items again instead of editing the already created item to only attach the file without special characters.
 
After a long discussion we agreed to prevent the user on the same form itself instead of saving it and ask user to edit it later.
 
NOTE: This is the case in OOTB SP List as well.
 
Solution:
Insert below script on your form


    function PreSaveAction() {
        var fileNames = document.getElementById('<%=hfExtensions.ClientID %>').value;
        var isInvalidFile = "";
        var attachment;
        var invalid = "no";
        var filename = "";
        var fileNameSpecialCharacters = new RegExp("[~#%&*{}<>;?/+|\"]");
        var attachmentID = document.getElementById("idAttachmentsTable");
        for (var k = 0; k < attachmentID.getElementsByTagName("span").length; k++) {

            try {
                attachment = attachmentID.getElementsByTagName("span")[k].firstChild;
                filename = attachment.data;
                for (var h = 0; h < fileNames.split(',').length; h++) {
                    if (filename.split('.')[filename.split('.').length - 1] == fileNames.split(',')[h]) {
                        isInvalidFile = "invalid";
                        break;
                    }
                }
                if (isInvalidFile == "invalid") {
                    break;
                }
            }
            catch (e) {
            }
            if (fileNameSpecialCharacters.test(filename.split('\\')[filename.split('\\').length - 1])) {
                invalid = "yes";
                break;
            }
            else {
                invalid = "no";
            }
        }
        if (isInvalidFile == "invalid") {
            alert('The file you are attempting to save or retrieve has been blocked from this Web site by the server administrators');
            return false;
        }
        else {
            if (invalid == "no") {
                return true;
            }
            else {
                alert('A file name cannot contain any of the following characters: \\ / : * ? \" < > | # { } % ~ &.Please remove the character and try again.');
                return false;
            }
        }
    }

Tuesday, April 16, 2013

Content Type Hub for your Enterprise

Content Type Hub is the new verbage or term you might here a lot while talking about SharePoint 2010 as a enterprise level solution for document or record managment.

In my last assignment we have used Content Type Hub as it was an enterprise level Record Management System implementation. We have heard or known SharePoint as a Content Management System (CMS) since MOSS, but to me it actually comes with SharePoint 2010.

So when we started our implementation in early 2011, it was very tough for me as well to understand what it Content Type Hub and how it works. But thanks to SharePoint 4 Developer I found the answer in very easy language here.

Now, each new feature comes with their pros and cons. So, here are the cons or limitations for using the Content Type Hub.

Search with SharePoint 2010

Below are some of the best blogs for configuring and customizing Search and understand how search works with SharePoint 2010.

How to build a good enterprise level Search Center?

Usage of Content Source

How to restrict your user search experiance?

How to customize your user search experiance?

Managed Metadata Services (MMS) Limitations in SharePoint 2010

I am blogging back after a long long time. Since last 2 years i was very busy in one of the largest migration assignment from DCTM to SharePoint 2010.

We have build one of the largest Record Managment System in SharePoint 2010 history.

So I just wanted to share some of my learnings and findings from some other blogs here.

Managed MetaData is one of the biggest term from SharePoint 2010 for their Record/Document Management system, though there are some limitations associated with the same while using it effectively.

I have found those limitations here.

Do visit this, to know the biggest issue with MMS while deploying the site backup from one environment to another. Or you can write me to know more on my experience.