Monday, December 21, 2015

Upload content type template throgh CSOM

A few years ago I bloged, read it there, on how through server site code could upload new content types templates. This snippet of code do it through CSOM.
1 string targetUrl = ""; 2 string username = ""; 3 string password = ""; 4 string contentTypeId = "0x01010043A8F0AB23DEB745AF7BF9D49A69F638"; 5 string templatePath = ""; 6 7 using (ClientContext clientContext = new ClientContext(targetUrl)) 8 { 9 SecureString pwd = new SecureString(); 10 foreach (char c in password.ToCharArray()) pwd.AppendChar(c); 11 12 //clientContext.Credentials = new NetworkCredential(username, pwd); 13 clientContext.Credentials = new SharePointOnlineCredentials(username, pwd); 14 clientContext.RequestTimeout = Timeout.Infinite; 15 16 FileInfo file = new FileInfo(templatePath); 17 18 ContentType contentType = clientContext.Web.ContentTypes.GetById(contentTypeId); 19 Web web = clientContext.Web; 20 21 clientContext.Load(contentType, c => c.Name); 22 clientContext.Load(web, w => w.ServerRelativeUrl); 23 clientContext.ExecuteQuery(); 24 25 string resourcePath = string.Format("{0}_cts/{1}", web.ServerRelativeUrl, contentType.Name); 26 27 using (FileStream stream = file.OpenRead()) 28 { 29 30 FileCreationInformation templateFile = new FileCreationInformation() 31 { 32 ContentStream = stream, 33 Url = file.Name, 34 Overwrite = true 35 }; 36 37 Folder folder = web.GetFolderByServerRelativeUrl(resourcePath); 38 folder.Files.Add(templateFile); 39 contentType.DocumentTemplate = file.Name; 40 contentType.Update(false); 41 clientContext.ExecuteQuery(); 42 } 43 }

Friday, November 6, 2015

Office Word add-ins: Insert template base on Word, Part 3

This is a three-part blog series to introduce Word Add-in and how to use Open XML SDK for JavaScript. This is the last post of this three-part blog series on Office Word add-ins: Insert template base on Word is a resources post.

Resources

The two first links is for the openxmldeveloper.org and where to download the code.
- openxmldeveloper - http://openxmldeveloper.org/
- mdownload - https://openxmlsdkjs.codeplex.com/

The third link is to a snippet collection with sample for the build in Word add-in https://officesnippetexplorer.azurewebsites.net/#/snippets/word

The fourth link is to the MSDN section “JavaScript API for Office”, where everything about the API for Office Add-ins can be found. https://msdn.microsoft.com/en-us/library/office/fp142185.aspx

Related blog posts

Read the first part here http://blog.andersdissing.com/2015/11/office-word-add-ins-insert-template-part1.html
Read the second part here http://blog.andersdissing.com/2015/11/office-word-add-ins-insert-template-part2.html




Thursday, November 5, 2015

Office Word add-ins: Insert template base on Word, Part 2

This is the second post of this three-part blog series to introduce Word Add-in and how to use Open XML SDK for JavaScript. This post describe what framework I use to read whole Word file and interact with the current Word file.

Read the first part here http://blog.andersdissing.com/2015/11/office-word-add-ins-insert-template-part1.html

Add JavaScript frameworks to the Word Add-in

To interact with an Office document, I use the JavaScript API that comes with the Office add-in. But read parts or the whole document, from the API service, I use the Open XML SDK for JavaScript. This API has the ability to create a JavaScript object base on a base64 string and the notion of Word packages. This allows the JavaScript FlatOpc object to insert to the Word file.

Ressources:

OpenXML Developer - http://openxmldeveloper.org/ Download - https://openxmlsdkjs.codeplex.com/

Steps, add OpenXmlSDK, retrieve and insert template:

  1. First we need to download and add the openxmlsdkjs to the project.
    Before:
    clip_image001
    After:
    clip_image002 
  2. Modify the Home.html, head html tag, to include the openxml.js and dependence.
    Before:
    clip_image004
    After:
    clip_image006 
  3. Modify the Home.html, body html tag, to include a button
    clip_image007 
  4. Modify the Home.js
    - Bind the click event to a function
    - Create the click event function
    clip_image008 
  5. Fill in the logic of the insertTemplate function
    - Get template (base 64 string) from API service
    - Create a openXml.OpenXmlPackage object
    - Save the OpenXmlPackage to a FlacOpt object
    - Use the build-in Word API to insert the FlacOpt object to the body of the Word file
    clip_image010 
  6. The test
    - F5 to run the project
    - Click the ‘insert template’ in the Add-in. clip_image012

Related blog posts

Read the first part of the Office Word add-ins: Insert template base on Word here http://blog.andersdissing.com/2015/11/office-word-add-ins-insert-template-part1.html




Wednesday, November 4, 2015

Office Word add-ins: Insert template base on Word, Part 1

This is a three-part blog series to introduce Word Add-in and how to use Open XML SDK for JavaScript. The goal of these blog posts is to create an Office add-in that can insert a Word base template into another Word file. By describe how to create a Word add-in that can read a Word file and use the file as a template. This allow an user to choice and insert a prepare template and the templates is easy created in Word.

User case:

  1. An user starts Word with the add-in.
  2. The user presses a button in the add-in.
  3. The add-in call a services for the template.
  4. The add-in insert the template in the current Word file.

Steps, Create the project and setup API services to return a template:

  1. Create a Word add-in project base on the “App for Office”.clip_image002clip_image004clip_image006
  2. Add a WebAPI webservice to the project.
    Add a Web API Controller Class to the project. N.B.! remember to post-fixet the filename with Controller!
    clip_image008Edit the ApiController to return a base64 string.
    This example read a docx file from a sub folder “Documetns” in the website that host the Add-in.
    clip_image010Add a Global.asax to the project to allow ApiController to be start and call.
    clip_image012

    clip_image013
    Add the folder “Documents” file to the project and create a Word file named template1.docx. And the project structure and Word file shout look something like this.clip_image015

Related blog posts


Friday, September 18, 2015

SPBG ERFA omkring CRM og SharePoint i København

Hej SharePointer
Kom til SPBG erfa møde torsdag den 22. oktober, i København, og mød Kasper Birch Olsen og Svend Erik Laursen. Kasper er Principal Solution Architect og Svend Erik er Principal Architect begge fra ProActive.
Kasper og Svend Erik vil give en kort introduktion til hvad CRM og derefter vil vi vise hvordan man kan integrere CRM med SharePoint og dele deres erfaring fra forskelle kunde cases.
Vi afholder mødet hos Progressive fra kl. 17:00 til ca. 19 tiden. S.U den 18. oktober. Tilmelding sker på http://spbgerfa201501022.eventbrite.com

Friday, September 11, 2015

Error when running the prerequisites for SharePoint Server 2016 Preview

When running the prerequisites setup for SharePoint Server 2016 Preview on my Windows Server 2012 (not R2), I got an error “application server role, web server (iis) role: configuration error”.

It seem not to a SharePoint Server 2016 Preview specific error for Christopher (http://www.someshinyobject.com) got a matching error and posted a blog about it. With a PowerShell script, that installs the Windows feature need for SharePoint.

Link to the blog post: http://www.someshinyobject.com/posts/server-2012-r2-and-sharepoint-2013-the-tool-was-unable-to-install-application-server-role-web

Wednesday, July 22, 2015

Wait for timerjob to finish

I had an old PowerShell latying around. The PowerShell script wait for a given timerjob to be finished.
1 $sleeptime = 5
2 $timerjobname = "MetadataHubTimerJob"
3
4 $timerjob = Get-SPTimerJob | Where {$_.Name -eq $timerjobname}
5 if($timerjob)
6 {
7 $countBefore = $timerjob.HistoryEntries | select "EndTime"
8
9 $timerjob.RunNow()
10 "Waiting for timerjob: $($timerjob.Name) to finish"
11 while($true)
12 {
13 Start-Sleep -Seconds $sleeptime
14 $countAfter = $timerjob.HistoryEntries | select "EndTime"
15
16 if($countAfter.Count -gt $countBefore.Count)
17 {
18 "The timejob $($timerjob.Name) is done"
19 break
20 }
21 else
22 {
23 "Still waiting on timerjob: $($timerjob.Name) to finish..."
24 }
25 }
26 }
27 else
28 {
29 "The timerjob: $($timerjob.Name) was not found."
30 }

Wednesday, July 8, 2015

PowerShell script to restart application pools, with remote Powershell

Has a follow up on my blog post about a PowerShell script to restart application pools. This script do it with remote PowerShell

$computername = "myserver"
$script = {   
    Import-Module WebAdministration
    (Get-Item "IIS:\Sites\*"| Select-Object applicationPool).applicationPool | % { Restart-WebAppPool $_ }
}
$cred = Get-Credential
$remotesession = New-PSSession -ComputerName $computername -Credential $cred
Invoke-Command -Session $remotesession -ScriptBlock $script

PowerShell script to restart application pools

Two line PowerShell script to restart all application pools on a server

1 #Import WebAdministration
2 Import-Module WebAdministration
3 #Find, pipe and restart
4 (Get-Item "IIS:\Sites\*" | Select-Object applicationPool).applicationPool | % { Restart-WebAppPool $_ }
5

Tuesday, June 30, 2015

Unable to type in visual studio

After not using an Azure VM in a few weeks, I booted machine and started Visual Studio to get some work done. But I could not type in any documents. It was like all the document was in some kind of read only mode :S After rebooting (several times) I found this stackoverflow post. http://stackoverflow.com/questions/24825925/unable-to-type-in-visual-studio

In short my resharpers project cache was broken and I need to delete it.

Saturday, June 20, 2015

SharePoint Crawler Troubleshooting using fiddler

A nice blog by Matthew McDermott (https://twitter.com/MatthewMcD/) to using fiddler as a proxy to see how SharePoints search crawlers is build its web request and what the web site reposonse back with.

Link to blog post: http://www.ableblue.com/blog/archive/2012/01/04/troubleshooting-sharepoint-search-crawl/

Tuesday, May 26, 2015

DevCamp 2015

In danish:

Kom til et gratis heldags arrangement omkring udvikling i Office 365 i København den 16 juni. På dagen gennemgår vi at udvikle apps til Office 365 med standard web teknologier der udvider funktionaliteten af Office og Office 365. (kendskab til SharePoint udvikling ikke nødvendig!). Du kan læse mere om arrangement på http://spbg.dk/SitePages/DevCamp2015.aspx hvor du også kan tilmelde dig. Arrangement bliver afhold hos Nets, Lautrupbjerg 10, 2750 Ballerup og starter kl 9:00 og slutter omkring 17:00.

Læse mere på http://spbg.dk/SitePages/DevCamp2015.aspx

Tuesday, April 28, 2015

Register to attend the Microsoft MVP Virtual Conference

Hi All – I wanted to let you know about a great free event that Microsoft and the MVPs are putting on, May 14th & 15th.  Join Microsoft MVPs from the Americas’ region as they share their knowledge and real-world expertise during a free event, the MVP Virtual Conference.

The MVP Virtual Conference will showcase 95 sessions of content for IT Pros, Developers and Consumer experts designed to help you navigate life in a mobile-first, cloud-first world.  Microsoft’s Corporate Vice President of Developer Platform, Steve Guggenheimer, will be on hand to deliver the opening Key Note Address.

Why attend MVP V-Conf? The conference will have 5 tracks, IT Pro English, Dev English, Consumer English, Portuguese mixed sessions & Spanish mixed sessions, there is something for everyone!

Come learn from the best and brightest in the tech world today. All of the sessions will all be delivered by the Americas’ Region Microsoft MVPs. These MVPs are experts who present at premiere conferences, independent community events and local user groups all over the globe.

This is a technical conference focused on helping attendees to learn and develop skills for everything from everyday technical work to wackier weekend projects. Whether it is on the IT Pro, Dev or Consumer side of things, you can bet that the content of MVP V-Conf will be cutting edge, exciting and relevant.

Be sure to register quickly to hold your spot and tell your friends & colleagues.

The conference will be widely covered on social media, you can join the conversation by following @MVPAward and using the hashtag #MVPvConf.

Tuesday, March 31, 2015

Sunday, March 8, 2015

SharePoint dinner i Århus

I forbindelse med Office Camp, i Århus, bliver der også afholdt SPBG SharePoint dinner.

Selv om du ikke deltager til Office Camp, er du mere end velkommen til at deltage til Sharepoint dinner.

SharePoint dinner er den 27/3-2015 kl 18 på The Burger Joint (http://theburgerjoint.dk/).

Hvad SharePoint dinner går ud på, kan du læse om det her:(http://sharepointbrugergruppe.dk/Pages/Hvad%20er%20SharePoint%20dinner.aspx)

Obs! Tilmelding sker ved på http://spdinner20150327.eventbrite.com og seneste den mandag den 23. marts.

Thursday, March 5, 2015

A C# thing in PowerShell. String.Format

A PowerShell tips. A feature that I often use in C # is string.Format https://msdn.microsoft.com/en-us/library/system.string.format(v=vs.110).aspx. This function can also use the PowerShell. This can be done via [string]::Format("template {0}", $varb1) or you can call -f parameter after a string in PowerShell, for example. "template {0}" -f $ varb1

Wednesday, February 25, 2015

Call Exchange Web servies API through PowerShell

I had to test whether a given user has a given meeting requests in a calendar in Exchange. Therefore, I wrote this little piece of PowerShell script, that’s using Microsoft Exchange Web Services Managed API, to find the Exchange server based on user's email address. Then make a call to the user's calendar, where I could check if there was create meeting request.

Step 1. Download and execute the the Microsoft Exchange Web Services Managed API 2.0 http://www.microsoft.com/en-us/download/details.aspx?id=35371

Step 2. Change the PowerShell script
Change this variable:
$exchangeversion
$pathToExchangeDll
$folderName
$usersmtpadress
$userlogin
$userdomain
$userpassword

Step 3. Run the PowerShell script

1 $exchangeversion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010
2 $pathToExchangeDll = "c:\ExchangeWebserviceApi\Microsoft.Exchange.WebServices.dll"
3 $folderName = [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Calendar
4 $usersmtpadress = "user@domain.dk"
5 $userlogin = "userlogind"
6 $userdomain = "domain"
7 $userpassword = "P@ssword!"
8
9 #callback function
10 function AutodiscoverCallback
11 {
12 param (
13 [System.String]
14 $Url
15 )
16 return $true
17 }
18 $callback = ${function:AutodiscoverCallback}
19 $service = new-object "Microsoft.Exchange.WebServices.Data.ExchangeService" $exchangeversion
20 $principle = new-object "Microsoft.Exchange.WebServices.Data.Mailbox" $usersmtpadress
21 $folder = new-object "Microsoft.Exchange.WebServices.Data.FolderId" $folderName, $principle
22 $connectingIdType = [Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress
23 [system.reflection.assembly]::loadfile($pathToExchangeDll) | Out-Null #e.g. c:\ExchangeWebserviceApi\Microsoft.Exchange.WebServices.dll
24
25 #setup call for Exchange web services
26 $service.Credentials = new-object "System.Net.NetworkCredential" $userlogin, $userpassword, $userdomain
27 $impersonatedUserId = new-object "Microsoft.Exchange.WebServices.Data.ImpersonatedUserId" $connectingIdType, $usersmtpadress
28 $service.ImpersonatedUserId = $impersonatedUserId
29 $service.AutodiscoverUrl($usersmtpadress, $callback)
30
31 #calling Exchange web services
32 $principleCalendar = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, $folder)
33 "User {0}'s calendar" -f $userlogin
34 $principleCalendar

Friday, February 20, 2015

Call for Speakers

Vores venner fra der danske SQL Community, er i gang med at planlægge den tredje SQL Saturday i København.
En SQL Saturday er et heldags event med indlæg omkring SQL server, SQL rapporting og SQL analysis.
Arrangøren af den kommende SQL saturday, ville rigtig gerne have et SharePoint spor denne gang. Så hvis du har noget SharePoint på hjertet, og selv om det ikke har noget med SQL at gøre og har lyst til at tale, så vil jeg gerne høre fra dig.
Du kan læse mere om SQL saturday på deres hjemmeside http://www.sqlsaturday.com/413/. Eventet bliver afholdt den 19/9/2015 på ITU.