Etykiety

Pokazywanie postów oznaczonych etykietą SharePoint 2010. Pokaż wszystkie posty
Pokazywanie postów oznaczonych etykietą SharePoint 2010. Pokaż wszystkie posty

niedziela, 21 czerwca 2015

Create SendTo connection programmatically

private const string CONTENT_ORGANIZER_URL = "/_vti_bin/officialfile.asmx";

/// To run this code without Access Denied error, RemoteAdministratorAccessDenied must be set False. Do it with PowerShell:
/// $contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
/// $contentService.RemoteAdministratorAccessDenied = $false
/// $contentService.Update()
SPSecurity.RunWithElevatedPrivileges(delegate()
{
SPWebApplication webapp = newRC.WebApplication;
       var newhost = new SPOfficialFileHost(true);
       newhost.OfficialFileUrl = new Uri("url of site with content organizer feature on" + CONTENT_ORGANIZER_URL);
       newhost.OfficialFileName = "Your connection name";
       newhost.Explanation = "Your connection description";
       newhost.ShowOnSendToMenu = false;
       newhost.Action = SPOfficialFileAction.Move;
webapp.OfficialFileHosts.Add(newhost);
webapp.Update();
});


Code sample of using ListViewWebPart

Application Page:

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
   <asp:UpdatePanel ID="panelLV" runat="server" UpdateMode="Conditional"></asp:UpdatePanel>
</asp:Content>

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
   if (!IsPostBack)
   { 
      createLVWP();
   }
}

private void createLVWP()
{
   SPWeb web = SPContext.Current.Web;
   SPList list = web.GetList(
         SPUrlUtility.CombineUrl(web.ServerRelativeUrl, myListUrl));

   lvwp = new ListViewWebPart();
   lvwp.ListName = list.ID.ToString("B").ToUpper();
   lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
   lvwp.ChromeType = PartChromeType.None;
   
   filterLVWP();
   this.panelLV.ContentTemplateContainer.Controls.Add(lvwp);
}

private void filterLVWP()
{
   string query = string.Format(
@"<Contains>
<FieldRef Name='myFieldName' /><Value Type='Text'>{0}</Value>
</Contains>", myFieldValue);

   XmlDocument doc = new XmlDocument();
   doc.LoadXml(lvwp.ListViewXml);
   XmlNode queryNode = doc.SelectSingleNode("//Query");
   XmlNode whereNode = queryNode.SelectSingleNode("Where");
   if (whereNode != null)
      queryNode.RemoveChild(whereNode);

   XmlNode newNode = doc.CreateNode(XmlNodeType.Element, "Where", String.Empty);
   newNode.InnerXml = query.ToString();
   queryNode.AppendChild(newNode);
   lvwp.ListViewXml = doc.OuterXml;
}

How to use UpdatePanel with LVWP in SharePoint 2010 WebPart?

This is example of classic Web Part (i.e. not Visual Web Part) with UpdatePanel and ListViewWebPart put on it.

First assure that you have this using statement:
using System.Web.UI;
and you reference in your project System.Web.Extensions library. Otherwise you won’t be able to use UpdatePanel control.
Here is the sample WebPart class:

[ToolboxItemAttribute(false)]
public class MyWP : System.Web.UI.WebControls.WebParts.WebPart
{
    TextBox txtExample1;
    TextBox txtExample1;
    ListViewWebPart lvwp;
    SPList list;
    UpdatePanel panelMain;
   
    protected override void CreateChildControls()
    {
        panelMain = new UpdatePanel();
        panelMain.UpdateMode = UpdatePanelUpdateMode.Conditional;

        txtExample1 = new TextBox();
        txtExample2 = new TextBox();

        list = SPContext.Current.Web.GetList(SPUrlUtility.CombineUrl(SPContext.Current.Web.Url, "Lists/MyList"));
        lvwp = new ListViewWebPart();
        lvwp.ListName = list.ID.ToString("B").ToUpper();
        lvwp.ViewGuid = list.DefaultView.ID.ToString("B").ToUpper();
        lvwp.ChromeType = PartChromeType.None;

        Controls.Add(new LiteralControl(" Label1: "));
        Controls.Add(txtExample1);
        Controls.Add(new LiteralControl(" Label2: "));
        Controls.Add(txtExample1);
        panelMain.ContentTemplateContainer.Controls.Add(lvwp);
        this.Controls.Add(panelMain);
    }
}



czwartek, 10 kwietnia 2014

Change rendering of the List using XSL

I have a list definition in Visual Studio. Now I want to modify the rendering of the list views using XSL.
First I point my custom xsl file in the XslLink attribute in the list Schema.xml file:

<XslLink Default="TRUE">CustomLibrary.xsl</XslLink>

MailType is a custom column of type Choice and has the following options to choose: In, Out, Other.
I’d like to change two things:
  •  the way its values are displayed in the ListView: show icons instead of text
  • the column header of the ListView: instead of the default DisplayName, I want custom text “In/Out”


Here is the XSL file:

<xsl:stylesheet
       xmlns:x="http://www.w3.org/2001/XMLSchema"
       xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt"
       xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
       xmlns:msxsl="urn:schemas-microsoft-com:xslt"
       xmlns:SharePoint="Microsoft.SharePoint.WebControls"
       xmlns:ddwrt2="urn:frontpage:internal"
       xmlns:o="urn:schemas-microsoft-com:office:office">

<xsl:include href="/_layouts/xsl/main.xsl"/>
       <xsl:include href="/_layouts/xsl/internal.xsl"/>

       <xsl:template name="FieldRef_header.MailType" match="FieldRef[@Name='MailType']" mode="header">
             <th nowrap="nowrap" scope="col" onmouseover="OnChildColumn(this)">
                    <xsl:attribute name="class">ms-vh2</xsl:attribute>
                    <xsl:call-template name="dvt_headerfield">
                           <xsl:with-param name="fieldname">
                                  <xsl:value-of select="@Name"/>
                           </xsl:with-param>
                           <xsl:with-param name="fieldtitle">
                                  <xsl:value-of select="'In/Out'"/>
                           </xsl:with-param>
                           <xsl:with-param name="displayname">
                                  <xsl:value-of select="@DisplayName"/>
                           </xsl:with-param>
                           <xsl:with-param name="fieldtype">x:string</xsl:with-param>
                    </xsl:call-template>
             </th>
       </xsl:template>


<xsl:template name="FieldRef_body.MailType" match="FieldRef[@Name='MailType']" mode="body">
             <xsl:param name="thisNode" select="."/>
             <xsl:choose>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'In'">
                           <img src="/_layouts/images/gbwwain.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Out'">
                           <img src="/_layouts/images/gbwwaoof.png" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:when test="$thisNode/@*[name()=current()/@Name] = 'Other'">
                           <img src="/_layouts/images/generaldocument.gif" alt="Typ: {$thisNode/@MailType}" title="{$thisNode/@MailType}" />
                    </xsl:when>
                    <xsl:otherwise>
                           <span></span>
                    </xsl:otherwise>
             </xsl:choose>
       </xsl:template>
</xsl:stylesheet>

The above file needs to be deployed to the {SharePointRoot}\Template\Layouts\XSL\ folder.

Problem during deployment of BDC Model

First thing to check is Feature1.Template.xml. Chances are it lacks SiteUrl property. Here is example of correct xml code:
<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/">
  <Properties>
    <Property Key='SiteUrl' Value='http://...'/>
  </Properties>
</Feature>

How to hide Ribbon items

The Ribbon on the SharePoint Forms supports customization of the default tabs, groups, and controls.
In order to customize Ribbon item, you need to know the specific identifier (ID).
The IDs can be found in the CMDUI.xml file in the …\14\TEMPLATE\GLOBAL\XML directory or you can see them here: http://msdn.microsoft.com/en-us/library/ee537543.aspx
Here is the example of how to hide some ribbon items in the form’s code-behind:
protected void Page_Load(object sender, EventArgs e)
{
  SPRibbon rib = SPRibbon.GetCurrent(this);
  if (rib != null)
  {
    rib.TrimById("Ribbon.ListForm.Edit.Actions.DeleteItem");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.EditSeries");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.ClaimReleaseTask");
    rib.TrimById("Ribbon.ListForm.Edit.Actions.DistributionListsApproval");       
  }
}

poniedziałek, 18 listopada 2013

Polskie znaki Ł i Ś

W pliku
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\1045\FORM.js
zamienić
L_InsertCellLeftKey_TEXT=”L”   na   L_InsertCellLeftKey_TEXT=”false”
oraz
L_SplitCellKey_TEXT=”S”   na   L_SplitCellKey_TEXT=”false”

poniedziałek, 23 września 2013

SharePoint user - when there are changes in AD

When some user data change in AD (e.g. last name) this change in most cases is not properly synchronized to SharePoint site collection.
The following Power Shell commands may help:

$user = get-spuser -Identity domain\username -Web http://server:port
Set-SPuser -Identity $user -SyncFromAD

Sadly it doesn't help in case an account name in AD has been changed. Then we have an orphaned user situation and the solution is to delete the account in SharePoint.
If it's only one site collection with couple of users, the quick way is to do it manually via Site collection - go to this page: http://sitecollection/_catalogs/users/simple.aspx

wtorek, 26 marca 2013

How to tune list view of style "Preview Pane". Part 2: no selection on page load

Another problem with the list or library view with style "Preview Pane" is that when the page loads, no item on the list is selected and as a result no field values are displayed in the table.
To correct this behaviour you need the help of javascript and jquery library.
Run SharePoint Designer and go to the view edition. You have to place these statements into the view code:

<scriptlink id="ScriptLink1" name="jquery.min.js" loadafterui="false" localizable="false" runat="server"></scriptlink>
<script type="text/javascript">
jQuery(document).ready(function () { $("div.ms-ppleft table tr td.ms-vb-title").first().trigger("onfocus"); })
</script>
The above code assumes that the jquery library file "jquery.min.js" is placed in folder C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS.

How to tune list view of style "Preview Pane". Part 1: duplicated "Name" field


When list's or library's view has style "Preview Pane", it shows all items' names in the list and the rest of the fields for the currently selected item is shown in the table. I don't like that the "Name" field gets duplicated in the list and in the table.

To correct this situation, run the SharePoint Designer and go to the view edition.
The inner name of the "Name" field is different for the list (LinkTitle) and for the library (LinkFilename). You can check the fields shown in the view looking for the <ViewFields> section in the code:

<ViewFields>
  <FieldRef Name="LinkFilename"/>
  <FieldRef Name="CustomField"/>
  <FieldRef Name="Modified"/>
</ViewFields>

First change the order of the fields so the "Name" field has the last position. You can do it in code or in Web GUI. 

Now find in code section that is responsible for drawing the table with fields:


<table class="ms-formtable" border="0" cellpadding="0" cellspacing="0" width="100%">
  <xsl:for-each select="ViewFields/FieldRef[not(@Explicit='TRUE')]">
    <tr>
      <td nowrap="nowrap" valign="top" width="190px"  class="ms-formlabel">
        <nobr>
          <xsl:value-of select="@DisplayName"/>
        </nobr>
      </td>
      <td valign="top" class="ms-formbody" width="400px" id="n{position()}{$WPQ}">
        <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
      </td>
    </tr>
  </xsl:for-each>
</table>

Add the xsl:if statement to eliminate the Name field from the table:

<table class="ms-formtable" border="0" cellpadding="0" cellspacing="0" width="100%">
  <xsl:for-each select="ViewFields/FieldRef[not(@Explicit='TRUE')]">
    <xsl:if test="@Name!='LinkFilename'">
      <tr>
        <td nowrap="nowrap" valign="top" width="190px"  class="ms-formlabel">
          <nobr>
            <xsl:value-of select="@DisplayName"/>
          </nobr>
        </td>
        <td valign="top" class="ms-formbody" width="400px" id="n{position()}{$WPQ}">
          <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
        </td>
      </tr>
    </xsl:if>
  </xsl:for-each>
</table>

poniedziałek, 4 lutego 2013

Migrating WebApplication from SP2010 to SP2013

1. Take the backup of web application content database on SharePoint 2010  from sql server using Sql Server Management Studio

2. On SharePoint 2013 create new web application. Pay attention that on SharePoint 2010 your application probably has classic-mode authentication, while on SharePoint 2013 the default is claims-based authentication. To create classic-mode web application in a SharePoint 2013, execute this command in PowerShell:
New-SPWebApplication –name "<WebAppName>"
–Port <PortNumber>
–ApplicationPool "<AppPoolName>"
–ApplicationPoolAccount (Get-SPManagedAccount "<Domain>\<AccountName>")

To use an existing application pool, provide only application pool name, without account.


3. Deploy all required farm solutions to the new web application

4. Remove content database from newly created web application in Central Administration > Manage Content Databases

5. Detach or delete the content database using Sql Server Management Studio

6. Now restore the backuped database.

7. Attach the restored content database to new web application using PowerShell:

Mount-SPContentDatabase -Name <DatabaseName> -DatabaseServer <DBServerName> -WebApplication <WebAppURL>

środa, 28 listopada 2012

The ultimate way to delete SharePoint application service

i.e. Search Service Application:
stsadm.exe -o deleteconfigurationobject -id "[GUID]"

And that way you can get to know the id:
Get-SPServiceApplication |?{$_.name -eq "[ServiceApplicationName]"}


środa, 21 listopada 2012

How to rename Search Service Application databases

There are 3 databases related to Search Service Application:
  1. Administration
  2. Crawl
  3. Property
Go to Central Administration > Application Management > Manage service applications. Find on the list application of type “Search Service Application” and click on its name. Then click on the Modify button.
Now you can see these databases.
From Central Administration you can rename only the Crawl and Property databases.
For each database select Edit Properties and change the database name. “Pending update” message appears in the Pending Changes column. Then click on Apply topology changes button. Wait patiently, on my machine it took above 10 minutes to complete.
You cannot rename Administration database from Central Administration. Run Sharepoint Managemet Shell for this purpose.
Before renaming the database, you have to pause the Search Service. But first step is to get to know Search Service identity. You can read the id of your Search Service Application when you run this command:
Get-SPEnterpriseSearchServiceApplication

Pause the service:
Get-SPEnterpriseSearchServiceApplication -Identity " service_id " | Suspend-SPEnterpriseSearchServiceApplication

Rename the database:
Set-SPEnterpriseSearchServiceApplication -Identity " service_id " -DatabaseName "new_database_name" -DatabaseServer "sql_server_name"

Resume the service:
Get-SPEnterpriseSearchServiceApplication –Identity "service_id" | Resume-SPEnterpriseSearchServiceApplication

In case there were any problems with renaming the database, after suspending the service run the Sql Server Management Studio. From here you can rename the database or, what is much safer , make a copy of it. After you have rename the database "manually", run the Set-SPEnterpriseSearchServiceApplication command.

środa, 23 maja 2012

How to find out what is the site template?

First, run the Power Shell script:

$web = Get-SPWeb <Site URL>
write-host "Web Template:" $web.WebTemplate " | Web Template ID:" $web.WebTemplateId
$web.Dispose()


You now know the site template name and id. But to know the template title, as you see it when creating a new site from web interface, run this command:


Get-SPWebTemplate | Sort-Object "Name"


Here is a list of most popular site templates:


Site Definition                                                 
Site Template Name & ID
Team Site                                           
STS#0
Blank Site
STS#1
Document Workspace
STS#2
Blog
BLOG#0
Group Work Site
SGS#0
Visio Process Repository
VISPRUS#0
Basic Meeting Workspace
MPS#0
Blank Meeting Workspace
MPS#1
Decision Meeting Workspace
MPS#2
Social Meeting Workspace
MPS#3
Multipage Meeting Workspace
MPS#4
Assets Web Database
ACCSRV#1
Charitable Contributions Web Database
ACCSRV#3
Contacts Web Database               
ACCSRV#41
Issues Web Database
ACCSRV#6
Projects Web Database
ACCSRV#5
Document Center
BDR#0
Records Center
OFFILE#1
Business Intelligence Center
BICenterSite#0
My Site Host
SPSMSITEHOST#0
Personalization Site
SPSMSITE#0
Enterprise Search Center
SRCHCEN#0
Basic Search Center
SRCHCENTERLITE#0
FAST Search Center
SRCHCENTERFAST#0
Enterprise Wiki
ENTERWIKI#0
Publishing Portal
BLANKINTERNETCONTAINER#0
Publishing Site
CMSPUBLISHING#0


Export / Import site, list or document library

To export a site, list, or document library, you can use either Windows PowerShell or Central Administration. But to import them, you can use only Windows PowerShell. So let's focus on the Power Shell.

Export command:
Export-SPWeb -Identity <Site URL> [-ItemUrl <Object URL>] -Path  <Export file name> [-IncludeUserSecurity] [-IncludeVersions] [-Force <True|False>] [-NoFileCompression] [-Verbose]
Import command:
Import-SPWeb -Identity <Site URL> -Path <Export file name> [-Force] [-NoFileCompression] [-Verbose]
-Force overwrites the export package if it already exists. During import use it to overwrite the list or library that you specified.

-NoFileCompression disables file compression in the export package. The export package is stored in the folder then. Use this parameter for performance reasons. If you used this option when exporting,  you have to specify it during import  as well.

-Verbose is used it to view the progress of the operation.

The site that you are importing to must have a template that matches the template of the exported!


Here you can read how to find out what is the site template?

The site that you are importing to must have the same default language as the exported site!

wtorek, 27 marca 2012

Access denied to "Configure service accounts"

I was completely surprised to get "Access denied" message when trying to open "Configure service accounts" option in Central Administration > Security. My account was in the farm administrators group, wasn't it!

But to be in the farm administrators group was not enough. To get access to the "Configure service accounts" I had to add my account to the local Administrators group on the machine running Sharepoint server.















That's all!

wtorek, 10 stycznia 2012

Tips for configuring search center


1. People searching does not work...
... while searching global scope ("All Sites") returns proper results.


Go to the "CA > Manage service applications > your Search Service Application > Content Sources". Make sure that one of the content sources being crawled (most probably "Local SharePoint sites") has the following entry in start addresses: "sps3://server-name" - where server-name is your web application URL.

You now have to check the Search Crawling Account permissions. Go to the "Security > Specify web application user policy" and select your web application. Make sure that crawling account has Full Read permission.

Search Crawling Account also needs to have permissions to the User Profile Service Application. To check it, open "Manage service applications", highlight User Profile Service Application and click on the Administrators button at the ribbon. The required permission is "Retrieve People Data for Search Crawlers".

Run full crawl on the content source containing "sps3://server-name" start address.

Now your people searching should work...

2. Searching within contextual scope does not work...
... while searching global scope ("All Sites") returns proper results.

Go to the Central Administration and check the alternate access mappings for the zone Default. Then go to the "Manage service applications > your Search Service Application > Content Sources". One of the content sources defined there (most probably "Local SharePoint sites") pertains web application where search in contextual scope is not working. Check the start addresses: the host URL must be the same as defined in alternate access mappings for the zone Default.

SharePoint creates the entry in the content source whenever you create a web application. But you must remember that changing  alternate access mappings can cause the URLs listed in content source stop matching and then your contextual searching stops working.

3. You want to have searching results from contextual scope displayed on the same, customizable page, as searching results from global scope.


That's pretty easy. Go to the Site Collection Administration settings and choose "Search settings".
In the "Site Collection Search Dropdown Mode" select mode that allows contextual scope, otherwise the next setting - "Site Collection Search Results Page" - will be disabled.
Now you have to enter address of the page that the searching result will be displayed on - preferably the search results page from your Search Center:


poniedziałek, 5 grudnia 2011

Jak zmienić nazwę bazy danych dla SharePoint Central Administration (7 kroków do wolności od GUID-ów)


1. Uruchom SharePoint 2010 Management Shell

2. Utwórz nową, pustą bazę danych dla aplikacji Central Administration:

New-SPContentDatabase -Name MOSS_207_AdminContent -WebApplication http://plglisrv207:10000

3. Odczytaj ID bazy danych z GUIDem. Następująca komenda zwróci informacje na temat obu baz danych: z GUIDem i nowej, utworzonej w poprzednim kroku:

Get-SPWebApplication –Identity http://plglisrv207:10000 | Get-SPContentDatabase

4. Przenieś site collections z bazy danych z GUIDem do nowej bazy danych. Do identyfikacji baz danych użyj ID odczytanych w poprzednim kroku:

Get-SPSite -ContentDatabase 4d46caff-7bb0-4a47-bedf-76fdb983dd0f | Move-SPSite -DestinationDatabase 87db4860-036e-4b3b-9540-905352893b09





5. Zgodnie z zaleceniem, uruchom IISRESET z linii poleceń.

6. Możesz zweryfikować wykonane operacje, uruchamiając Central Administration > Application Management > Manage Content Databases.

7. Najwyższy czas pozbyć się bazy danych z GUIDem:

Remove-SPContentDatabase –Identity 4d46caff-7bb0-4a47-bedf-76fdb983dd0f


A co z pozostałymi bazami danych, które Sharepoint tak szczodrze tworzy na serwerze, każda rzecz jasna z GUIDem w nazwie? Polecam artykuł na Technecie: Rename or move service application databases (SharePoint Server 2010).