Tuesday, May 31, 2016

Upgrade MySite to SharePoint 2013 but the photos are not linking back

So I didn't want to follow the Microsoft recommended directions to upgrade mysite for upgrading the service applications for Metadata and the user profile service.   Which  was fine for the metadata service since they weren't using anything on it.   But the user profile service does present one issue, the photo, which is stored in the user profiles.  


But I do have all the pictures on the mysite since it is stored at the root web under the User Photos library.  


here is the script to update the user photos with powershell,   replace the TODO with your information:




[Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
$siteurl = "TODO fill in mysite url"
$site = New-Object Microsoft.SharePoint.SPSite($siteurl)
$context = [Microsoft.Office.Server.ServerContext]::GetContext($site)
write-host $site.RootWeb.Lists["User Photos"]
#Get list of photos
$list = $site.RootWeb.Lists["User Photos"]
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)
Write-host $list.Items.Count
foreach($listitem in $list.Items)
{
    if($listitem["Name"].ToString().Contains("LThumb") )
    {
      #  Write-host $listitem["Name"].ToString()
        $user = $listitem["Name"].ToString().Replace("_", "\").Substring(0, $listitem["Name"].ToString().LastIndexOf("_"))
    #    write-host $user
        $fullphotourl = $siteurl + "User%20Photos/Profile%20Pictures/" + $listitem["Name"].ToString();
        write-host $fullphotourl
        if ($upm.UserExists($user))
        {
            $profile = $upm.GetUserProfile($user)
            $profile["PictureURL"].Value = $fullphotourl;
            $profile.Commit();
        }
   
    }
}
$site.Dispose()

Infopath template update does not complete apply when the document has digital signature

Encountered a strange issue where the form library template does not get fully applied with the changes when the document is signed using the browser.   If you open the form using the client, the templates gets applied and everything is kosher.


So tried all the basic things to get the browser form to upgrade or relink the form with the update template but no go.


Only one thing would work so, I had to write a little powershell script to open the forms with the InfoPath filler and submit it so that the form is saved with the template updates.




if the file is bigger than 50 MBs, you have to change the setting on the client machine.  it is defaulted to 50MB but you have files that are bigger so the registry setting has to be changed to increase the FileSizeLimitInBytes value located at [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\WebClient\Parameters]

find the TODO and replace with your own value
--------------------------------------------------------

Import-Module "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -AssemblyName Microsoft.Office.Interop.InfoPath
#url
$site = "TODO:  url of the site"
#user name
$admin = "TODO: account name with domain.  I used user@domain"
#Get Password as secure String
$password = Read-Host "Enter Password" -AsSecureString
#Get the Client Context and Bind the Site Collection
$context = New-Object Microsoft.SharePoint.Client.ClientContext($site)
#Authenticate
$credentials = New-Object System.Net.NetworkCredential($admin , $password)
$context.Credentials = $credentials
write-host "authenicated"
$web = $context.Web
$context.Load($web)
$context.ExecuteQuery()
write-host $web.Title

$list = $context.Web.Lists.GetByTitle("TODO: ListName to be filled in")


#write-host $list.Title
$context.Load($list)
$context.ExecuteQuery()
write-host $list.Title
write-host $list.

$query = [Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery(1000, "Title");
$items = $list.GetItems($query);
$context.Load($items);
$context.ExecuteQuery();

 #$context.Url
write-host $items.Count
$iApp = New-Object  Microsoft.Office.Interop.InfoPath.ApplicationClass
#$sdoc = New-Objct Microsoft.Office.Interop.InfoPath.XDocumentClass
$versionMode = New-Object Microsoft.Office.Interop.InfoPath.XdDocumentVersionMode
foreach($li in $items)
{
    #write-host  $li["Title"].ToString()
   
    $url = "TODO: Url of the list" + $li["Title"].ToString()
  
   #write-host $url
   try
   {
    $xdoc = $iApp.XDocuments.Open($url) #, $versionMode.xdCanTransformSigned)
        $xdoc.Save()
            $xdoc.CloseDocument()
             write-host  "Done 1:  "  $li["Title"].ToString()
    }
    catch
    {
        try
        {
            $xdoc = $iApp.XDocuments.Open($url, 18)  # 16 for $versionMode.xdCanTransformSigned + 2 for xdUseExistingVersion)
             $xdoc.Save()
            $xdoc.CloseDocument()
             write-host  "Done 2:  "  $li["Title"].ToString()
        }
        catch {
            $ErrorMessage = $_.Exception.Message
          
             write-host  "ERROR:  " $ErrorMessage " ::: " $li["Title"].ToString()
        }
    }
   
   
}

$context.Dispose()