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 }
Monday, December 21, 2015
Upload content type template throgh CSOM
Friday, November 6, 2015
Office Word add-ins: Insert template base on Word, Part 3
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.htmlRead 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
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:
- First we need to download and add the openxmlsdkjs to the project.
Before:
After:
- Modify the Home.html, head html tag, to include the openxml.js and dependence.
Before:
After:
- Modify the Home.html, body html tag, to include a button
- Modify the Home.js
- Bind the click event to a function
- Create the click event function
- 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
- The test
- F5 to run the project
- Click the ‘insert template’ in the Add-in.
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.htmlWednesday, November 4, 2015
Office Word add-ins: Insert template base on Word, Part 1
User case:
- An user starts Word with the add-in.
- The user presses a button in the add-in.
- The add-in call a services for the template.
- The add-in insert the template in the current Word file.
Steps, Create the project and setup API services to return a template:
- Create a Word add-in project base on the “App for Office”.
- 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!
Edit 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.
Add a Global.asax to the project to allow ApiController to be start and call.
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.
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
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
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
Debug Knockout
A shout-out to Ryan Niemeyer (https://twitter.com/RPNiemeyer) for a great blog about debug and troubleshooting strategies for Knockout at http://www.knockmeout.net/2013/06/knockout-debugging-strategies-plugin.html
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.