Showing posts with label SharePoint. Show all posts
Showing posts with label SharePoint. Show all posts

Thursday, 6 July 2017

Error: Group Not Found in SharePoint

Today while programatically adding user in SharePoint group I was getting error "Group Not Found" in my custom workflow.

The error was getting thrown at below line:
SPGroup grpViewer = workflowProperties.Web.Groups["GroupName"];

After some digging, I found that the error was coming since the group was not having permission on site. After giving read permission for the group on site, the error was gone.

Hope this helps!!!!

Friday, 3 July 2015

How to download all deployed wsp solution files in SharePoint

Usually SharePoint admin guys takes backup of content DB and all physical files if they want to create replica of existing SharePoint site when actual site is down.

But that will not complete solves the solution, if there are any custom solutions already deployed.

So, admin guys needs those solution files.
To get those solution files which are deployed in SharePoint use the following power shell command to get all deployed solution files.

$pathName = "<PATH to Save files>"
foreach ($solution in Get-SPSolution)   
{
     $solid = $Solution.SolutionID
     $title = $Solution.Name
     $filename = $Solution.SolutionFile.Name
     $solution.SolutionFile.SaveAs("$pathName\$filename") 
}

Ref: http://ukreddysharepoint2010.blogspot.in/2015/05/how-to-download-all-deployed-wsp.html

Hope this helps!!!

When to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

Below table give us the idea on when to use BeforeProperties, AfterProperties, properties.ListItem in event receiver

Library
BeforeProperties
AfterProperties
properties.ListItem
ItemAdding
No value
No value
Null
ItemAdded
No value
No value
New value
ItemUpdating
Original value
Changed value
Original value
ItemUpdated
Original value
Changed value
Changed value
ItemDeleting
No value
No value
Original value
ItemDeleted
No value
No value
Null

Hope this helps!!!

How to find out SPUser belongs to Specific Group

How can I find out programmatically if current user belongs to some group on sharepoint website?

We can use below code:

SPWeb site = SPContext.Current.Web;
SPGroup managerGroup = site.Groups["Your_Group_Name"];

bool isManager = site.IsCurrentUserMemberOfGroup(managerGroup.ID);

Hope this helps!!!!

Wednesday, 27 May 2015

Reserved querystring parameter in Sharepoint

Below querystring parameters are reserved in SharePoint and using them may give unpredictable results.

  • FeatureId
  • ListTemplate
  • List
  • ID
  • VersionNo
  • ContentTypeId
  • RootFolder
  • View
  • FolderCTID
  • Mode
  • Type
  • PageVersion
  • IsDlg
  • Title
  • _V3List_

To ensure that the creation of the SPContext object does not fail your application should ensure that your query string parameters are different from those listed above.

Reference: http://blogs.technet.com/b/stefan_gossner/archive/2009/01/30/querystring-parameters-you-should-not-use-in-your-sharepoint-application.aspx

Tuesday, 26 May 2015

How to exclude or skip part of page content from SharePoint search crawler

To do this we have to use the "noindex" class, like this,

<div class="noindex"> footer </div>

This will be helpful if you want to avoid footer to get crawled in search. Because of the fact that the footer is part of the master page the crawler may index every single page that inherits from the master page. This will cause misleading and wrong search results for the visitors of the site.

Wednesday, 6 May 2015

How to access SharePoint server “Outgoing E-Mail Settings” from code?

Outgoing email setting are configured in central administration at path:

Central Admin -> System Settings -> Configure outgoing e-mail settings

Below is the code to access outgoing e-mail settings using object model:

//Get the site ID
Guid siteID = SPContext.Current.Site.ID;
protected string GetSMTPHostName()
{
    using (SPSite site = new SPSite(siteID))
    {
      //Get the SMTP host name from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailServiceInstance.Parent.Name;
    }
}
protected string GetFromEmailID()
{
    using (SPSite site = new SPSite(siteID))
    {
      //Get the “from email address” from “Outgoing e-mail settings”
      return site.WebApplication.OutboundMailSenderAddress;

    }
}

Namespace: Microsoft.SharePoint.Administration
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Tuesday, 5 May 2015

How to get document library size using PowerShell?

Below is the PowerShell script which will show the size of Particular library:

   [System.reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint, Version=12.0.0.0,             Culture=neutral, PublicKeyToken=71e9bce111e9429c”)
    [System.Reflection.Assembly]::Load(“Microsoft.SharePoint.Portal, Version=12.0.0.0,   Culture=neutral, PublicKeyToken=71e9bce111e9429c”)


    Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

    $siteURL = "YourSiteURL" 
    $site = new-object Microsoft.SharePoint.SPSite($siteURL)


    foreach ($web in $site.AllWebs)
    {
     foreach ($list in $web.Lists)
    {

            if($list.BaseType -eq "DocumentLibrary")   
          {

if($list.Title -eq "YourDocumentLibraryTitle")
{
        $listSize = 0
       foreach ($item in $list.items) 
            { 
              $listSize += ($item.file).length
            }
         "Web: "+$web.Title+", Library Name: "+$list.Title+", Size: "+[Math]::Round(($listSize/1KB),2)+"KB"     
}
    }
    }
    }


Hope this helps!!!!

Tuesday, 2 September 2014

Adding user in SharePoint group programmatically

Below is the code to add user in SharePoint group programmatically:


 using (SPSite site = new SPSite(Respective Site URL))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    try
                    {
                        SPUser requiredUser = web.EnsureUser("domainname\\username");

                        if (requiredUser != null)
                        {
                            SPGroup requiredGroup = web.Groups["groupName"];
                            if (requiredGroup != null)
                                requiredGroup.AddUser(requiredUser);
                        }
                   
                    }
                    catch (Exception ex)
                    {
                     
                    }                 
                }
            }

Thursday, 21 August 2014

How to check which edition of SharePoint is running on server?

You can check the SharePoint Edition by going into Central Administration.

In Central Administration go to Upgrade and Migration --> Convert farm license type.
It will show you current edition. For e.g. SharePoint Server with Enterprise Client Access License.

Hope this helps.!!!!!


Friday, 10 February 2012

Input mask on textbox in SharePoint list form

Yesterday on LinkedIn I saw one discussion where one of group member asked a query about how to create Input mask on text box in SharePoint List form.

While searching on internet I found this post. In this post Author opened the new form in SharePoint designer, added custom new form and then added jQuery code on page.

But what if I do not have SharePoint designer.

So instead opening page in SharePoint designer, I added CEWP on NewForm.aspx

And then I did some changes in original code, Instead of custom style I used Title of the field. And I inserted below code in Source editor of the CEWP.

<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js" type="text/javascript" ></script>
<script language="javascript" src="http://jquery-joshbush.googlecode.com/files/jquery.maskedinput-1.2.2.min.js" type="text/javascript" ></script>
<script language="javascript" type="text/javascript">

jQuery(function($){
   $("input[title='Phone']").mask("(999) 999-9999? Ext.99999");
});

</script>

And it worked for me. Have a look at below screenshot.








Reference:
http://www.a2zdotnet.com/View.aspx?Id=194 (Original post)
http://digitalbush.com/projects/masked-input-plugin/





Thursday, 2 February 2012

Filter document library view by file type

Sometimes we get requirement such that document library should display files with certain file type.
For an example, I want to create view which will display only word documents.

Here is how we need to create our view
  1. Go to Document library settings.
  2. Create view
  3. Name the view: Word documents
  4. Go to Filter and Select "Show items only when following is true"
  5. Choose Name > Contains > .doc (See below screenshot)
  6. Or When Column > Name > Contains > docx (See below screenshot)











When we will select this view it will display word documents.






Monday, 9 January 2012

To display Item ID in display and edit forms of SharePoint list items

In some cases, we may need to show ID field in display or edit form of a SharePoint list item.

There are some simple steps given on "Path to SharePoint" to achieve this http://blog.pathtosharepoint.com/2009/01/18/item-id-in-display-and-edit-forms/

Cheers!!!


Thursday, 20 October 2011

How to add if else if statement in calculated columns of SharePoint 2007

This is what I want to achieve

if(status = "Bad")
then rating = 1
else if(status = "Good")
then rating = 2
else if(status == "Excellent")
then rating = 3

to achieve this I created a calculated column "Rating" and added below formula

=IF([status]="Bad",1,IF([status]="Good",2,IF([status]="Excellent",3)))

And it was returning perfect results required to me.

There are also lots of sample formulas available at below link:
http://office.microsoft.com/en-us/sharepoint-server-help/CH010176029.aspx?CTT=97
Related Posts Plugin for WordPress, Blogger...