środa, 30 października 2013

Make Visual Studio to add .dll to GAC after each build

Go to Project > Properties and enter the following into the Post-build event command line:
(on Windows Server 2012)
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe" /i
"$(TargetPath)" /f

(on Windows Server 2008)
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\gacutil.exe" /i "$(TargetPath)" /f

Remember to:
  • run Visual Studio as Administrator
  • sign the assembly

wtorek, 22 października 2013

Replace columns in DataTable and by the way insert at specified position (code snippet)



DataTable table = GetSomeDataTable();

table.Columns.Add("NewNumber", typeof(int)).SetOrdinal(table.Columns["OldColumn1"].Ordinal);
table.Columns.Add("NewText", typeof(string)).SetOrdinal(table.Columns["OldColumn2"].Ordinal);

foreach (DataRow row in table.Rows)
{
  row["NewNumber"] = Transform1(row["OldColumn1"]);
  row["NewText"] = Transform2(row["OldColumn2"]);
}

table.Columns.Remove("OldColumn1");
table.Columns.Remove("OldColumn2");


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, 10 września 2013

Przeniesienie SharePoint Server 2013 na nową maszynę wirtualną

Na poprzedniej maszynie:


  1. Sporządzić listę baz danych używanych przez SharePoint server: Central Administration -> Upgrade and Migration -> Review database status
  2. Shutdown IIS
  3. Zatrzymać wszystkie windows services związane z SharePoint-em.

Przenosiny:


  1. Przenieść wszystkie bazy danych na nowy SQL server (Backup+Restore)
  2. Przenieść obraz maszyny wirtualnej z SharePoint server. Jeśli była to instalacja SharePoint+SQL Express na jednej maszynie, poprzedni punkt jest oczywiście zbędny. 

Na nowej maszynie:

  1. Uruchomić Sql Server Configuration Manager w celu zdefiniowania aliasów. Należy utworzyć identyczne aliasy dla SQL Native Client [VERSION] Configuration (dla 32 i 64 bitowego):
    - w polu Alias Name wpisać nazwę Sql Servera z poprzedniej maszyny,
    - skopiować nazwę do pola Server i zmodyfikować wpis o nazwę bieżącej maszyny.
  2. Aby aliasy działały, trzeba używać protokołu TCP/IP. W Sql Server Configuration Manager wejść do SQL Server Network Configuration>Protocols for SHAREPOINT. TCP/IP powinien być włączony a Shared Memory wyłączony.
  3. Wykonać restart maszyny
  4. Uruchomić sharepoint-owe windows services,  
  5. Odszukać windows service SQL Server Browser i uruchomić/upewnić się że działa.
  6. Sprawdzić czy SharePoint łączy się z właściwym serwerem bazy danych za pomocą procedury składowanej sp_who,
  7. Należy zmienić nazwę serwera ShaerPointa za pomocą programu stsadm.exe. Dla wersji 2013 znajduje się on w folderze: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\BIN.
    Polecenie zmiany nazwy serwera:
    stsadm -o renameserver -oldservername <YourOldServerName> -newservername <YourNewServerName>

czwartek, 23 maja 2013

Enable Session State in Sharepoint 2013

1. Run in PowerShell:
Enable-SPSessionStateService –DatabaseName "<your database name>"
or, if you don't mind guids in database names:
Enable-SPSessionStateService -DefaultProvision

2. Open web.config of the WebApplication where you want SessionState to be enabled and change line
<pages enableSessionState="false" (...)
to
<pages enableSessionState="true" (...)

3. Restart IIS

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.