Hide a field from SharePoint Designer Form - NewForm/DisplayForm/EditForm

To hide a field from any of the SharePoint Designer Form we usually create a custom form and edit the code and add a style attribute as style="display:none" in <tr> element.

But what if you do not want to create a custom form and hide the field on the default form? Is it possible? The answer is YES.

You can hide the field on default SPD form via PowerShell command without having to create a custom form.

Open SharePoint Management Shell and type the following commands. The below example hides a field from a NewForm.

$web = Get-SPWeb webUrl
$list = $web.Lists.TryGetList("ListName")
    $field = $list.Fields["FieldName"]
    $field.ShowInNewForm = $false

You can similarly execute the below command for DisplayForm and EditForm. The only statement you need to change is:
$field.ShowInDisplayForm = $false
$field.ShowInEditForm = $false

Determining the type of SharePoint List Template

There are three methods that I know to identify the type of SharePoint List template. All the methods has easy steps to execute and find the type:

     1. Using Browser Method
·         Open that SharePoint List which you want to identify its type and ensure to open that list in AllItems.aspx view. Then in your web browser click on the menu bar > View > Source or simply right click on the page and select View Source and search for ctx.listTemplate.
·         Once you find ctx.listTemplate then match its value with the available List Template IDs (Click Here).

     2. Using PowerShell Command
·         Connect to your SharePoint Server and open SharePoint 2010 Management Shell.
·         Type the following commands that would retrieve all list and libraries in a web site. Search the name of your target list/library and match the Type_Client with List Template IDs given in above link.

>> $SPWeb = Get-SPWeb “http://yourSharePointServer/
>> $SPWeb.ListTemplates | Select Name, type, type_client, Description


     3. Using XML
·         Go to List/Library Settings and from the browser URL copy the string that appears after List=
·         Open this web site http://meyerweb.com/eric/tools/dencoder/ and paste the copied string and press Decode button.
·         Now copy the decoded string paste it somewhere in notepad.
·         Get the SharePoint web site URL under which the list/library is created.
·         Now construct the URL as below example:

·         In the above URL all remain same except the website URL before /_vti_bin/ and copy your decoded List ID and put it inside the braces { } after List=
·         Then finally copy the entire constructed URL and paste into IE and press Enter.
·        In the XML returned by browser search for text ServerTemplate and match its value with the List Template ID, link provided in point 1.

Picture Library SlideShow Web Part not displaying image in original size

This is a known fact that out-of-the-box Picture Library SlideShow Web Part does not display the images in its original size. Further more, unfortunately it is not supported to configure in web part what image type (original, web or thumbnail) should be displayed in Slideshow.

The JavaScript code described below allows to display original images (without re-sizing) in Slideshow Web Part. In order to display original image the technique is to override the ShowPic function. For embedding JavaScript on page, use Content Editor web part (CEWP) on the same page where you have also inserted your SlideShow web part.

<script type="text/javascript">

function SlideshowObjectInitializer() {

  ShowPic = (function(ShowPicOrig) {
      return function() {

           var ssObj = arguments[0];  //SlideShow object
           var curPicIdx=ssObj.index; //current picture index

           ShowPicOrig.apply(this, arguments); //call original ShowPic

           //apply some changes to display original picture in SlideShow control
           ssObj.image.src = ssObj.linkArray[curPicIdx]; //display original image instead of web image
           //change picture & container size to auto instead of fixed (by default web image size is used)
             var cell = ssObj.cell; 
             cell.style.width = 'auto';
             cell.style.height = 'auto';
             cell.style.display = '';
             var pcell = ssObj.cell.parentNode; 
           pcell.style.width = 'auto';
             pcell.style.height = 'auto';


ExecuteOrDelayUntilScriptLoaded(SlideshowObjectInitializer, 'imglib.js');
In the above given code you can adjust the size by modifying these lines/values:
The value '100%' can be changed to '90%' or '80%' and even in pixels you can mention the size, example:

Attached files in InfoPath are not indexed by SharePoint

This is a frequent and common question that every SharePoint/InfoPath developer come across at some point of time. The fact is attached files in InfoPath forms are not indexed. When you upload a file in an InfoPath form using the File Attachment control, InfoPath saves not only the binary data, but in a binary way extra information like name etc. When SharePoint Search is indexing, it finds the InfoPath xml file, it can read inside, but then the indexer finds a string of strange characters that the file attachment control has encoded and eventually the attached file content is not indexed.
The other work around would be to upload the file in a document library and providing the link in InfoPath form.
You may find some blog over web saying that SharePoint does index file attachments. But this is not true and not confirmed by Microsoft. But rather I have confirm from Microsoft experts that SharePoint does not indexes attachments in InfoPath form.

You may check this http://sharepointbeeeye.com/infopath-2010-a-better-file-attachment-solution/ article. It says it provides a better file attachment solution in InfoPath. I haven't tried this solution myself but you can try and let me know.

Using SPSecurity.RunWithElevatedPrivileges with SPContext class

Using SPSecurity.RunWithElevatedPrivileges with SPContext class.

If you have implemented your code similar to the Code Snippet 1 then you might run into exception. Many developers implement their code, similar to the Code Snippet 1 and runs into exception such as Access Denied, “sign in as a different user”. This is because… the below code is not the correct way of using SPSecurity.RunWithElevatedPrivileges

When you declare SPSite elevatedSite = SPContext.Current.Site; or SPWeb elevatedWeb = SPContext.Current.Web;

these statements runs with the current login user permission and not the System Account. Therefore you might face an Access Denied exception when updating a list or any content since the code is running under current login user credentials who might have no add/contribute access on the list. No matter if you have declared
SPContext under SPSecurity.RunWithElevatedPrivileges, still the code will execute with the current login user permission.

Code Snippet 1 (Incorrect way):

      SPSite spSite = SPContext.Current.Site;

      using (SPWeb spWeb = spSite.OpenWeb())
         // Performing administrative actions here will give Access Denied exception.

Code Snippet 2 (Correct Way):

Guid spSiteGUID = SPContext.Current.Site.ID;
Guid spWebGUID = SPContext.Current.Site.OpenWeb().ID;

    using (SPSite elevatedSiteColl = new SPSite(spSiteGUID))
       using (SPWeb elevatedWeb = elevatedSiteColl.OpenWeb(spWebGUID))
         //your code…

The above Code Snippet 2 automatically disposes the SPContext object and the SPSite and SPWeb objects are also automatically disposed once they leave the code block. No need to dispose SPSite and SPWeb objects explicitly when they are declared in using statement.

So the bottom line is SPContext does not works under SPSecurity.RunWithElevatedPrivileges.