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)
             ssObj.image.setAttribute('height','100%'); 
             ssObj.image.setAttribute('width','100%'); 
             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';
      };
  })(ShowPic);

}  


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




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):

SPSecurity.RunWithElevatedPrivileges(delegate()
{
      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;

SPSecurity.RunWithElevatedPrivileges(delegate()
{
    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.

Easiest way to populate a drop-down list control with SharePoint custom list column values

There are numerous ways to populate a drop-down list control with SharePoint custom list column values. But for me the below seems to be the easiest one.

You should populate the drop-down list on a page load event as given in below code. You can copy the exact below code with few changes as what column values you want to populate and your drop-down list control ID/Name.


I have used here 
SPQuery since I want to order the column values alphabetically, starting from ascending to descending. You can omit the SPQuery statement and directly specify the column value in spList.GetItems() method.

Example: SPListItemCollection spListColl = spList.GetItems("Title"); // Title is the column name. You can mention any column name of your choice.

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      Guid spSiteGUID = SPContext.Current.Site.ID;
      Guid spWebGUID = SPContext.Current.Site.RootWeb.ID;

      //Use above statement if your site is at root site or else below one.  
      //Guid spWebGUID = SPContext.Current.Site.OpenWeb().ID; 

      SPSecurity.RunWithElevatedPrivileges(delegate()
      {
         using (SPSite elevatedSiteColl = new SPSite(spSiteGUID))
         {
            using (SPWeb elevatedWeb = elevatedSiteColl.OpenWeb(spWebGUID))
            {
               SPList spList = elevatedWeb.Lists["QD Offices"];
               SPQuery spQuery = new SPQuery();
               spQuery.Query = "<OrderBy><FieldRef Name='Country'/></OrderBy>";
               SPListItemCollection spListColl = spList.GetItems(spQuery);
               foreach (SPListItem spItem in spListColl)
               {
                  string listItem = spItem["Title"].ToString();
                  ddl_location.Items.Add(listItem);
               }
            }
         }
      });
   }
}


Cheers !!

Open InfoPath Form from SharePoint Designer trigger email

In this article I will show you how you can create a hyperlink through which you can open a published InfoPath form from an email, triggered by SharePoint Designer 2010 Workflow.

In SP Designer Workflow, select "Set Variable Workflow" action and set the variable to the string specified in the below first image.

Text reference: First select [%Workflow Context:Current Site URL%] by clicking "Add or Change Lookup" button and select Data Source: Workflow Context; Field from source: Current Site URL, then same string as it is till Cases/, then select Current Item:Title, then write "&Source", then again [%Workflow Context:Current Site URL%] and finally write or copy the string "/Cases/Forms/AllItems.aspx&DefaultItemOpen=1"








In the second image, you can see there a link "here", by clicking this click an active InfoPath form will be opened in the web browser. [Just confirm that your InfoPath form is web browser enabled form].




















You can include this "here" link by clicking the small icon next to "Automatic".

Cheers !

Hope this small piece helps you...