Thursday, February 17, 2011

Folder with Title Column

When we create a Folder in a SharePoint(2007/2010) Document Library, in "Edit Properties" Page of the Folder we can only change the Name of it. Another point is that the Name of the Folder uses as a part of its URL. 
Sometimes there is a need to keep the Folder path URL short and also has a kind of description or user friendly name for your Folder. Out of the box, SharePoint default Folder Content Type doesn't support this for some reasons the Title column is hidden and there isn't the possibility of change it. To have such a Folder with Title column you can complete these steps:
  • Navigate to Site Settings > Site Content Types
  • Create a new Content Type and choose "Folder Content Types" as its Parent Content Type
  • Click on Title column of the new created content type and for its Column Settings choose
  • Go to your Document Library and add new created Content Type to it.

Monday, February 7, 2011

Filling fields using javascript and web services

Some days ago there was a request for filling a look up field in New Item page automatically according to the current user information. One of the ways of doing this, is coding for custom field but the other quick and easy way is using JavaScript and web services

1- Adding a field with default value of [Me] to hold the user name of current user
2- Adding a content Editor webpart in NewForm.aspx page of List and put the code below inside its source editor:

<script type="text/javascript" language="javascript">

    var siteCompleteURL = document.URL;
    componentList = siteCompleteURL.split('//');
    siteURL = componentList[1].split('/');

    var curUserLastName = new Array();
    var curUserID = new Array();
    var baseURL = componentList[0] + "//" + siteURL[0] + "/";
    var siteURL = componentList[0] + "//" + siteURL[0] + "/";

    //Get The Value Of Hidden UserName Field
    var curUser = document.getElementById('USERNAMEID').value;


    //Hide The UserName Field and its Label
    document.getElementById('
USERNAMEID').style.visibility='hidden';
    var nobrTags = new Array();
    nobrTags=document.getElementsByTagName('nobr');
    for (i = 0; i < nobrTags.length; i++) {
    if (nobrTags(i).innerHTML=='UserName')
      nobrTags(i).innerHTML='';
     }

    //Get The LookUp Filed Object
    var expOwnerCID='LOOKUPFIELDID';

    //GUID Of The List We Want To Query
    var listGUID = 'd6e7ebe5-79b1-4e92-b50a-adf6d4c79c6e';

    //Where Statement of Web service Request
    var whereStatement = "<Eq><FieldRef Name=\"_x0646__x0627__x0645__x0020__x06\" /><Value Type=\"User\">"+curUser+"</Value></Eq>";
   
    function GetRootUrl() {
        return siteURL;
    }

    function getNodeValue(obj, tag) {
        return obj.getElementsByTagName(tag)[0].firstChild.nodeValue;
    }

    function QueryListEx(listGuid, where, rowLimit, extractRows) {
        var a = new ActiveXObject("Microsoft.XMLHTTP");
        if (a == null) return null;
        a.Open("POST", GetRootUrl() + "_vti_bin/dspsts.asmx", false);
        a.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
        a.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/sharepoint/dsp/queryRequest");

        var d = '<?xml version=\"1.0\" encoding=\"utf-8\"?>'
    + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
    + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" "
    + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
    + " <soap:Header xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope\/\">"
    + " <dsp:versions xmlns:dsp=\"http://schemas.microsoft.com/sharepoint/dsp\">"
    + " <dsp:version>1.0</dsp:version>"
    + " </dsp:versions>"
    + " <dsp:request xmlns:dsp=\"http://schemas.microsoft.com/sharepoint/dsp\""
    + " service=\"DspSts\" document=\"content\" method=\"query\">"
    + " </dsp:request>"
    + " </soap:Header>"
    + "<soap:Body>"
    + "<queryRequest "
    + " xmlns=\"http://schemas.microsoft.com/sharepoint/dsp\">"
    + " <dsQuery select=\"/list[@id='" + listGuid + "']\""
    + " resultContent=\"dataOnly\""
    + " columnMapping=\"attribute\" resultRoot=\"Rows\" resultRow=\"Row\">"
    + " <Query RowLimit=\"" + rowLimit + "\">"
    + " <Where>" + where + "</Where>"
    + " </Query>"
    + " </dsQuery>"
    + " </queryRequest>"
    + "</soap:Body>"
    + "</soap:Envelope>";

        a.Send(d);

        if (a.status != 200)
            return null;

        var xmlDoc = a.responseXML;
        var responseElement = xmlDoc.getElementsByTagName("Row");
        var temp = '';        
        for (i = 0; i < responseElement.length; i++) {
            //Store Title Column Value
            curUserLastName[i] = responseElement[i].getAttribute('Title');

            var expOwner = curUserLastName[i];
           
            //To Execute This Code At The End Of The Page
            Sys.Application.add_load(function () {
                document.getElementById(
                getSubControlID(expOwnerCID, g_EntityEditorUpLevelId)).innerHTML = (expOwner);
                onKeyUpRw(expOwnerCID);
            });
                    }
    }
    QueryListEx(listGUID, whereStatement, 1, true);
</script>

A good source for JavaScript API that help me to complete this job:

Saturday, January 22, 2011

SharePoint 2010, PowerPivot and Oracle

Using PowerPivot Service in SharePoint 2010 is a good way of sharing PowerPivot sheets and doing data refresh without the need of installing PowerPivot Add-in on client's machine.

My first experience of using this service with Oracle 10.2.0.4, was a bit annoying but successful at the end. So, I want to share the points with people who stuck in similar situation and don't know what they should install on their SharePoint server to make a complete connection to Oracle database via already made PowerPivot workbooks.

Here I summarize those steps I have taken to get it works:
  • Installing and configuring SharePoint and PowerPivot as Microsoft explained in this article.
If get an unsuccessful error message during SQL Server 2008 what pointed out here (for those who missed the step there is a workaround) may solve your problem.
In this post the writer describe in Oracle 11G Client Tools  the problem related to the bug No. 3807408 has been resolved. I didn't try it myself but it seems a good alternative.
  • Adding the tnsnames.ora file in NETWORK folder of Oracle Home
  • Restarting the server

    Opening Post - Stay Hungry Stay Foolish

    It's a long time from my first decision of creating a blog to write about my working life. I've lived with SharePoint for 5 years, we spent lots of good and bad moments together, so I want to share my future experiences with this lovely creature here with others.
    and ....
    Today, finally in my birthday I broke the spell and start this blog to start another way of being, to Stay Hungry and Stay Foolish.