Pages

Thursday, November 15, 2012

Add Sections and Color to Surveys

Hi All
SharePoint provides rich functionalities via different types of SharePoint Lists and “Survey” is one of them. Let us see what is Survey?
  • SharePoint Survey is a kind of list when we want to poll other web site users on some topics.
  • Surveys features
    • Quickly create questions
    • Define how users their answers
When we need to use SharePoint Survey?
We could use the SharePoint Survey when an organization wants to collect the responses from various people about any event/ activity or on an any idea, we could use SharePoint Survey!
Users love the functionality provided by Survey inside SharePoint but they are frustrated when face its limitation like how to create sections and put their related section questions together (Bundle them) inside the Survey List

So below step-by-step solution will provide you to create questions and section formatting too.

Steps:

  1. Create the Section:
    1. Create a “Single line of text” question , give its default value as “SECTION” before you add any question for that section

  1. Go to your survey and click “Respond to this Survey” to display the Newform.aspx page
     
  2. Edit the URL to allow access to the web parts:
      append this to the end of the URL for the NewForm.aspx URL:  
                &ToolPaneView=2 
    and press Enter  
    http://yourserver/sites/yoursite/Lists/SurveyTest/NewForm.aspx?Source=.......overview.aspx&ToolPaneView=2
  3. Click “Add a Web Part” and add a Content Editor Web Part
     
  4. Move the Content Editor Web Part below the list web part
     
  5. Edit the web part, click the Source Editor button and add the JavaScript from below
     
  6. Save your changes and go test the survey!
<script>
 // hide the input textbox for the "description" text
 var x = document.getElementsByTagName("INPUT");
 var i=0;
 for (i=0; i<x.length; i++)
 {
  if (x[i].value=="SECTION")
  {
    x[i].style.display="none";
  }
 }
</script>

Add color to your surveys!

Just follow the steps above, but use the following JavaScript. Manually embed your HTML in the text of the question: "Please take time to respond this survey about <b><i>Important Stuff</i></b>. "
<script>
 // Fix tags to allow HTML
 var t = document.getElementsByTagName('table');
 for (var i=0; i<t.length; i++)
 {
   if (t[i].className=='ms-formtable')
   {
     var td = t[i].getElementsByTagName('td');
     for (var j=0;j<td.length;j++)
     {
       if (td[j].innerHTML.indexOf('&lt;') > -1)
       {
         td[j].innerHTML = td[j].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
       }
     }
   }
 }
</script>

Let us we want to add sections and color with HTML Style!
Use both JavaScript routines together:
<script>
 // hide the input textbox for the "description" text
 var x = document.getElementsByTagName("INPUT");
 var i=0;
 for (i=0; i<x.length; i++)
 {
  if (x[i].value=="SECTION")
  {
    x[i].style.display="none";
  }
 }

 // Fix tags to allow HTML
 var t = document.getElementsByTagName('table');
 for (var i=0; i<t.length; i++)
 {
   if (t[i].className=='ms-formtable')
   {
     var td = t[i].getElementsByTagName('td');
     for (var j=0;j<td.length;j++)
     {
       if (td[j].innerHTML.indexOf('&lt;') > -1)
       {
         td[j].innerHTML = td[j].innerHTML.replace(/&lt;/g,'<').replace(/&gt;/g,'>');
       }
     }
   }
 }
</script>

Loved SharePoint Customization Tricks!
Disha Shah

Wednesday, August 15, 2012

SharePoint 2007 Workflow Fail to Start(retrying) in Designer and Out-of-Box

Today I ran into one workflow error, "Fail to Start(retrying)". As usual not detail description is available which has frustrated me.

After looking here and around, I found that the Service Account which is used by my web-application is different from IIS identity account to SharePoint Central Administration.

Here are the steps to solve it.
 
Steps:

1. Open SharePoint Central administration -> Go to Operations.

2. Under Security configuration sections, go to service accounts.

3. On the service account screen in web application pool dropdown,select windows sharepoint services web application and in appplication pool drop down select the web application where the workflow is not working.

4. Now, Check the apppool account in configurable. This account should match the identity account for your web application in IIS. If it is not ; make it the same and everything goes works fine.


Hope this helps!!
Disha Shah

Monday, July 23, 2012

Sharepoint 2013 and presentations


Hello All

Wow, what a great news, Microsoft released SharePoint 2013 beta!!!!

To get started with it , Sharepoint 2013 presentations were released by Microsoft and can be downloaded at

http://www.microsoft.com/en-us/download/details.aspx?id=30361

So exicted !!!!

Disha Shah


Friday, July 13, 2012

Print Functionality of List Vew Webpart in SharePoint

Hello Friends

User wants to print the available listitems of a list from a ListViewWebpart in a page and they want to print only those records rather than entire page content (Left Navigation, breadcrumbs etc.) .

So we could not provide the "print" functionality from the browser so we have to include below javascript inside the Content Editor Webpat and now you have print functionality available for ListView webpart only.

Add a content editor webpart on same page where your ListViewWebpart resides.
Write this javascript in the content editor webpart.

<input onclick="javascript:void(PrintWebPart())" type="button" value="Print Page"/> <!-- copy and paste in to a content editor source editor web part --><script language="JavaScript">



<!-- Web Part/region to print -->
var WebPartElementID = "MSO_ContentTable";

//Function to print Web Part
function PrintWebPart()
{
 var bolWebPartFound = false;
 if (document.getElementById != null)
 {
  //Create html to print in new window
  var PrintingHTML = '<HTML>\n<HEAD>\n';
  //Take data from Head Tag
  if (document.getElementsByTagName != null)
   {
   var HeadData= document.getElementsByTagName("HEAD");
   if (HeadData.length > 0)
    PrintingHTML += HeadData[0].innerHTML;
   }
  PrintingHTML += '\n</HEAD>\n<BODY>\n';
  var WebPartData = document.getElementById(WebPartElementID);
  if (WebPartData != null)
  {
   PrintingHTML += WebPartData.innerHTML;
   bolWebPartFound = true;
  }
  else
  {
   bolWebPartFound = false;
   alert ('Cannot Find Web Part');
  }
 }
 PrintingHTML += '\n</BODY>\n</HTML>';
 //Open new window to print
 if (bolWebPartFound)
 {
  var PrintingWindow = window.open("","PrintWebPart", "toolbar,width=800,height=600,scrollbars,resizable,menubar");
  PrintingWindow.document.open();
  PrintingWindow.document.write(PrintingHTML);
  // Open Print Window
  PrintingWindow.print();
 }
}</script>

Now you all set for print the listitems of listviewwebpart in SharePoint Pae.

Disha Shah

Thursday, July 5, 2012

Associate an SharePoint Designer workflow with a specific task list

Hello All,

If we would like to associate a different SharePoint Task List to SharePoint Designer workflow from more than available Task Lists, there is not any direct way or user interface to do this.

The configuration for which task List is configured to SharePoint Designer Workflow is stored  inside the wfconfig.xml file. This is not an recommended way to do this.

If there are multiple task list available inside SharePoint site, SharePoint Designer Workflow picks up the first Task List.

So if we want to attach Task List of our own choice , we need to follow these steps.

1> Create a task list which lists first as Task List.

2> In SharePoint Designer, create a new workflow and compile it (click Finish in the Workflow Designer)

3> Now rename that task list from SharePoint User Interface.

That's it!!!You are all set with the SharePoint Designer 2007 Workflow with your desired Task List.

Disha Shah

Wednesday, July 4, 2012

SharePoint PDF Files - Open in AdobeReader

Hello

Users found difficulty when they open any PDF files which are in Document Library, it always 
opens in browser and if they close it, it will close SharePoint Portal. If they would like to 
continue work inside the SharePoint Portal, they have to re-open SharePoint Portal.

So how to solve this? Please follow the below steps to change Adobe Reader settings to open 
PDF files.

1.       Click Start from your desktop
2.       Go to All Programs
3.       Open the Adobe Reader program:
4.       Select Preferences from Edit menu:
5.       From Internet from the Categories list and uncheck the Display PDF in browser option:
Once these setting are changed the PDF will no longer open in the browser window.  Problem Solved!!!


Disha Shah

Sunday, May 6, 2012

How to get currency field formatting which includes comma and $ sign in SharePoint Designer Workflow Email Activity

Problem:
I ran into one issue that by using SharePoint Designer Workflow, when it send email which contains “Currency” field in Email Activity it is not formatting  which shows commas and $ sign. It was irritating.
Solution:
After working on couple of hours, I found out solution (Such a simple) create one calculated column and make that column of String type and put the formula as “=DOLLAR(Amount,2)” and now include that field in Email Activity.
Whoooo!!!!!It is working like charm!!!!
Disha Shah


Friday, March 30, 2012

Customize the Homepage of SharePoint Blog Sites for Blog Posts Webpart

Hello Friends

The purpose of today Blog is how we can customize view of Posts for Blog Site.
Actually I want to add the new fields on the homepage of the blog site template’s summary view web part for each of the posts.

Let us see how can we do this. Here is step by step process to do this

1. I assume that You have already created your blog site, Add custom column inside the Posts List , in my case it is DelegatedBy which is Person or Group field type.

2. I have downloaded this custom blog.xsl file and upload it to a Site Assets or any other Document Library of your choice. Search for “DelegatedBy” where we added this field to the output which is the only customization that was 
performed on the original XSL.

3. Open the blog site homepage and edit it in SharePoint Designer. Here, you’ll want to click on the Posts web part and add the DelegatedBy column for the field to be displayed in the view.



4. We need to include a link reference to the custom XSL that you had uploaded in Step 2.



5. Save changes that you’ve made in SharePoint Designer and browse to your blog site , magic will happen .

Enjoy Blog Site!!!

Thanks
Disha Shah


Wednesday, March 14, 2012

Apply CSS for SPGridView Programatically in Webpart

Hello Friends

I have been working on webpart in which I was using SPGridView. Now I want to apply  fore-color to one column inside the SPGridView. When I tried with everything and none of them was working , every time it gets color from CSS file then I tried below line it works like magic!!!

oGridColCourse.ItemStyle.CssClass = "color: #0000F5 !important;";

Happy Coding!!!
Disha Shah

Tuesday, March 6, 2012

Move/Migrate SharePoint List Attachments to Document Library with Created and Modified Date

Hello

We have faced one problem about SharePoint Search . We have SharePoint list in which we have items and it has attachments, but SharePoint Search could not look inside Documents which are stored as Attachments in List. So to make it work we have to move all attachments inside the document library so SharePoint Search can crawl and return the results :).

So to provide Keyword Search we need to Move the SharePoint Attachments to Document Library so that we can search in SharePoint Search.

Here is code which will move SharePoint List Attachments to Document Library.

SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               using (SPSite site = new SPSite("SiteURL"))
               {
                   SPList docDestination = site.RootWeb.Lists["DocName"];
                   SPFolder fldRoot = site.RootWeb.Folders[docDestination.Title];
                   SPFileCollection flColl = null;
                   SPList lstAttachment = site.RootWeb.Lists["ListName"];
                   foreach (SPListItem lstItem in lstAttachment.Items)
                   {
                       if (lstItem.Attachments != null && lstItem.Attachments.Count > 0)
                       {
                           foreach (String strName in lstItem.Attachments)
                           {
                               flColl = fldRoot.Files;
                               SPListItem listtem = docDestination.Items.Add();
                               SPFile FileCopy = lstItem.ParentList.ParentWeb.GetFile(lstItem.Attachments.UrlPrefix + strName);

                               string destFile = flColl.Folder.Url + "/" + FileCopy.Name;
                               byte[] fileData = FileCopy.OpenBinary();

                               SPFile flAdded = flColl.Add(destFile, fileData, site.RootWeb.CurrentUser, site.RootWeb.CurrentUser, Convert.ToDateTime(lstItem[SPBuiltInFieldId.Created]), Convert.ToDateTime(lstItem[SPBuiltInFieldId.Modified]));
                               SPListItem item = flAdded.Item;
                               item[SPBuiltInFieldId.Created] = Convert.ToDateTime(lstItem[SPBuiltInFieldId.Created]);
                               item[SPBuiltInFieldId.Modified] = Convert.ToDateTime(lstItem[SPBuiltInFieldId.Modified]);
                               flAdded.Item.Update();
                           }

                       }
                   }
               }
           });

Disha Shah

How to Copy ListItem from One List to Another List

Hello

Here is code how to copy ListItem from one list to another list from eventhandler.
Make sure both list has same List Field Structure.

Here is Code

public override void ItemAdded(SPItemEventProperties properties)
       {

           if (properties.List.Title.Equals("ListA"))
           {
               SPListItem CopyItem = properties.Web.Lists["ListB"].Items.Add();

               foreach (SPField f in properties.ListItem.Fields)
               {
                   //Copy all except attachments.
                   if (!f.ReadOnlyField && f.InternalName != "Attachments"
                       && null != properties.ListItem[f.InternalName])
                   {
                       CopyItem[f.InternalName] = properties.ListItem[f.InternalName];
                   }
               }


               foreach (string fileName in properties.ListItem.Attachments)
               {
                   SPFile file = properties.ListItem.ParentList.ParentWeb.GetFile(properties.ListItem.Attachments.UrlPrefix + fileName);
                   byte[] imageData = file.OpenBinary();
                   CopyItem.Attachments.Add(fileName, imageData);
               }
               CopyItem.Update();

           }
       }

Hope it helps!!!

Disha Shah

Thursday, March 1, 2012

How to get username from JQuery

Hello Friends


Use below Jquery to get the Current User name
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Title",
                debug: false
});

Use below code to get the ID for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "ID",
                debug: false
});

Use below code to get the LoginName for Current User
var thisUserAccount = $().SPServices.SPGetCurrentUser({
                fieldName: "Name",
                debug: false
});

Disha Shah

jQuery is undefined in IE / spservices is null or not an object in IE

I just hated this error when I was working with JQuery. It is working perfectly OK with other browsers but in IE it just makes me crazy.

Then I figured out problem and that was the referencing of files.

I was using  jquery-1.6.1.min.js file from Internet and this file jquery.SPServices-0.6.2.min.js from document library.

Actually the problem with those files were I was referring jquery-1.6.1.min.js from Web and jquery.SPServices-0.6.2.min.js  from document Library and then I downloaded the jquery-1.6.1.min.js file and uploaded to document library where I have put the other file. Then it works like charm.

Disha Shah