Ads

Thursday, 16 March 2017

Configure Business Data Connectivity Service (BDC) Permissions

If you need to assign permissions on the Business Data Connectivity Service you just created, and you can do that by going to Sharepoint 2010 Central Administration. Once there, go to Application Management, then Manage Service Applications.

Choose Business Data Connectivity:

And choose the Content Type you created in Step 1, then set the permission:

It will now open a window to let you choose users to give permission to, it can come from an Active Directory or Forms Authentication User, you can also assign different permisssions per user or group:

Choose what's applicable to you and hit OK. Now, everything is ready.

Create an External List in SharePoint 2010 using Sharepoint Designer & BCS

Next, you will be exposing that table operations you just configured through an External List. First is you have to go to your navigation and choose List and Libraries, then choose External List

Once you click that, you will be presented with an External Content Type Picker and you will be able to view the Content Type you created a while ago on step 1, choose that and hit OK:

Now name your new external list and give it a description:

At this point, it will now be available on the External List Library. Click your external list to view its properties.

At this point, it has created the needed forms which are the Display Item, Display List, Edit and New Form.


Create an External Content Type using sharepoint 2010 designer & BCS

Now fire up your Sharepoint Designer 2010 and if you don't have one, you can download it here, once you are in, open your Team Site, then choose external content type, then create a new one:

Once you click that, it will open the Content Type Definitions, now place your Content Type Name, then click External System to define your Database Connection:

Now click Add Connection:

It will ask you different data source types, you can choose from .Net Type, WCF Service and SQL Server. We are now interested in SQL Server which lets you connect to a SQL Server Database. But before we move ahead, I will discuss a bit on the other two types as this adds flexibility on the Data Connections you might need later on. First it is a .NET Type which allows you to connect to a .NET Assembly which might be a third party or you developed it on your own and the next type is a WCF Service which lets you connect to a Webservice or a Metadata Exchange.
Ok, back to choosing SQL Server Connection, choosing it will prompt you to set the connection parameters:

Once you set it, your database objects will now be available on the Data Source Explorer.

Now choose the Table you need to expose and right click on it and create the operation you need. In this case, we select all operations so it will do read item, read list, create, update and delete in one shot.

Now, it will ask you some Operation Properties and Parameters, we will just click through next during the whole process.

Now the Parameters Configuration, we will just click next for now, but in short this window will:
  • configure the Data Source Elements on that table
  • require a field on save
  • define the field as a time stamp
  • show the field on the picker if you use this as a reference field on another Sharepoint list
  • and lots more

Now the Filter Parameter - this will let you filter the results the external list is grabbing from SQL so that it won't be slow loading the Sharepoint page especially if you have lots of rows. But for now, we also click next and let the default values handle it.

Now at this point, you have created the needed operations for the table you have chosen.

Now save your work by clicking that diskette icon on top:

Tuesday, 14 March 2017

C# code to create page layout in SharePoint 2010 using visual studio 2010

We normally use SharePoint Designer to create page layout. We can also do this by using visual studio.

Here we are article page as parent page. So need to activate two features
       a) SharePoint Server Publishing Infrastructure. [Site Collection Feature]
       b) SharePoint Server Publishing. [Manage Site Features]

If these two features are not activated then we wont see article page content type in Content Types. see the image.
activate these two features
1) Open visual studio --> File--> New --> Project --> Select SP 2010 --> Select Content Type  template --> project name.
3) Specify URL location for debugging and deploying this solution as sandbox solution for testing purpose only.
4) Choose Content Type from the drop down here am selecting 'Article Page' and Click on Next.
5) Now it will automatically open Elements.xml file of ContentType1. Now modifying Name of the Content Type and save the file.
6) Now Add Module for actual pagelayout name it as PageLayoutModule
By default module has two files one is Elements.xml and sample.txt
7) Now delete sample.txt file from PageLayoutModule
8) Now adding pagelayout page i.e UdayPageLayout.aspx to PageLayoutModule.
9) Design pagelayout. Here am adding one table in that am adding three webpart zones.
These webpart zones are used to place webpart.
here the code which i was used.

 <%@ Page Language="C#" Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation"
    Assembly="Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:content contentplaceholderid="PlaceHolderPageTitle" runat="server">
<SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server" />
</asp:content>
<asp:content contentplaceholderid="PlaceHolderMain" runat="server">
<table cellspacing="0" border="0" width="100%" cellpadding="0>
  <tr>
       <td width="100%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Top" Title="loc:Top" />
       </td>
       </tr>
       <tr>
       <td>
       <table width="100%">
       <tr>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Left" Title="loc:left" />
       </td>
       <td width="50%">
       <WebPartPages:WebPartZone runat="server" FrameType="TitleBarOnly" ID="Right" Title="loc:right" />
       </td>
       </tr>
       </table>
       </td>
       </tr>
       </table>
</asp:content>

10) Now open Elements.xml which is under PageLayoutModule and it looks like this.
11) Now change File tag's URL attribute because inorder to display your custom pagelayout in pagelayouts(which is in ribbon while the page in edit mode).
12) Now am adding properties to page layout. in this we specify Title of the page layout and ContentType i.e pagelayout content type and PublishingAssociatedContentType i.e name of the parent content type and Content Type ID of the Elements.xml which is under ContentType1.
And also Add URL attribute in Module tag.
13) Now open Features-->Feature1, ContentType1 and PageLayoutModule are in Items in the Solution.
Move these two items to Items in the Feature.
15) Now deployee the solution.
After successfully solution deploye. The page layout is available at http://<<server>>:<<port>>/_Catalogs/masterpage (_Catalogs/masterpage) is specified in pagelayoutmodule.
To go that page follow these steps
16) Now open your site --> site actions -->site settings, Click on Master pages and layouts which is uder Galleries.
17) Now you can find newly deployed pagelayout file in the list of files and its status as "Draft".
18) Now checkin the newly added pagelayout file. we can do it in two ways. one is through ribbon and through item menu.
19) While checkin select major version and add your comments and click on "OK".
20) Now the pagelayout status changes to pending it means we need to approve it.
Select the pagelayout and click on "Approve/Reject" from ribbon.
21) Then select "Approved" radio button in Approval Status. Click on "OK".
22) Now the pagelayout file status is approved, so that pagelayout is available.
23) Now Go to Site Actions --> More Options.
24) Select Page in left panel and click on Publishing page.Now click on Create.
25) Now you can see newly added pagelayout as (Name of the content type which is in Elements.xml file under layout1) Title value in Elements.xml which is under PageLayoutModule.i.e (CustomePagelayoutSample) Custome Page Layout.
now click on Create.
26) Now you can aslo see the newly added content page layout in page layouts(which is in ribbon).
Now you can add your webparts in webpart zones. And CheckIn Then Publish the page.
Refer: c-sharpcorner

Tuesday, 7 March 2017

C# code to get Last Modified Date of a SharePoint Site/web Programmatically

using (SPSite siteCollection = new SPSite("siteurl"))
{
  SPWebCollection sites = siteCollection.AllWebs;

  foreach (SPWeb site in sites)
  {
    DateTime dt = site.RegionalSettings.TimeZone.UTCToLocalTime(site.LastItemModifiedDate);
    Console.WriteLine("site::::{0} Modified time::::{1}", site.Title, dt.ToString());

  }
}




Use C# code to create new Web Application in Sharepoint 2010 Enabling FBA


SPWebApplicationBuilder webAppBuilder = new SPWebApplicationBuilder(SPFarm.Local);
webAppBuilder.Port = portNo;webAppBuilder.ApplicationPoolId = "IIS application ID";
webAppBuilder.IdentityType = IdentityType.SpecificUser;
webAppBuilder.ManagedAccount = mngAcc;
webAppBuilder.RootDirectory = new DirectoryInfo("physical path of web application"));
webAppBuilder.ServerComment = "Server comment";
webAppBuilder.UseNTLMExclusively = true;
webAppBuilder.AllowAnonymousAccess = false;
webAppBuilder.CreateNewDatabase = true;
webAppBuilder.DatabaseServer = "SQL Server name";
webAppBuilder.DatabaseName = "Database name";
if ("SQL Authentication is selected")
{
   webAppBuilder.DatabaseUsername = "username";
   webAppBuilder.DatabasePassword = "password";
}
newApplication = webAppBuilder.Create();
SPFormsAuthenticationProvider fbaAuthProvider = new SPFormsAuthenticationProvider(membershipProvider, roleManager);

newApplication.UseClaimsAuthentication = true;
newApplication.IisSettings[SPUrlZone.Default].AddClaimsAuthenticationProvider(fbaAuthProvider);
newApplication.Update();
newApplication.Provision();

C# code to check user permission in SharePoint list

The following sample shows how to check adding list item permissions for the current user.
using (SPSite spSite = new SPSite("http://MySiteUrl"))
{
  using (SPWeb spWeb = spSite.OpenWeb())
  {
    // Get the current user.
    SPUser currentUser = spWeb .SiteUsers[HttpContext.Current.User.Identity.Name.ToString()];
    // Get the list.
    SPList spList = spWeb.Lists["MyList"];
    // Variable to determine permission.
    bool userPermission = spList.DoesUserHavePermissions(currentUser, SPBasePermissions.AddListItems);
    if ( userPermission )
    {
      // Perform operation here.
    }
  }
}

The local variable "userPermission" will set to True if the user can add items in list otherwise it will set to false.
Similarly,
For viewing list item
   bool userPermission = spList.DoesUserHavePermissions(loginUser, SPBasePermissions.ViewListItems);
For editing list item
   bool userPermission = spList.DoesUserHavePermissions(loginUser, SPBasePermissions.EditListItems);
For deleting list item
   bool userPermission = spList.DoesUserHavePermissions(loginUser, SPBasePermissions.DeleteListItems);

Ads