Tuesday, December 24, 2013

App Designs in SharePoint 2013

copyright from: www.shillier.com

3/18/2013 Update: After presenting this material at a few user groups, I decided this article needs a better structure to present the ideas. So I have updated the table to reflect more nuance than just "good" and "bad". I'm interested in feedback as I am using this as a cornerstone for many presentations. Catch me on Twitter @ScotHillier.
The SharePoint 2013 app model supports three hosting models and two client APIs. This means that there are 12 permutations of app design as shown in the table below. In this post, I’ll briefly explain when you should use each app design.
Key
Key

Excellent ChoiceExcellent Choice
SharePoint-Hosted App, JavaScript, REST
SharePoint-Hosted apps must use JavaScript and can use either REST or CSOM (aka, JSOM). However, REST is by far the preferred approach. Why? Bringing the SharePoint context to the client is a uniquely-SharePoint idea that no other technology uses. REST is a standard that many technologies understand. Your code is a lot more “standard” when you use REST. Furthermore, key libraries such as jQuery already support REST.
Cloud-Hosted apps, C#, CSOM
Cloud-hosted apps (meaning both provider-hosted and autohosted) can use JavaScript/REST, C#/REST, or C#/CSOM. Again, some combinations are better than others.
When working with cloud-hosted apps, you often have to work with OAuth tokens. The TokenHelper class, which is included in Visual Studio makes this much easier. So, immediately you can see that C# is a better choice than JavaScript where tokens are important. JavaScript does have a role to play, but it is primarily when you need to use the cross-domain library to overcome firewall limitations.
Once you have concluded that C# is the way to go, you’ll discover that writing CSOM code is much easier than REST. CSOM can be used synchronously in the managed object model, which makes the code very simple and straightforward. REST calls, on the other hand, have some serious drawbacks. First, they require async round trips to the server to acquire the FormDigest from SharePoint. Second, you have to create POST messages by hand in code, which is ugly.

Cross-Domain SupportCross-Domain Support
Cloud-Hosted, JavaScript, CSOM
JavaScript/CSOM (aka JSOM) requires a SharePoint context. In classic JSOM, the context is created in code within a page that is hosted in SharePoint. When you consider that cloud-hosted apps never run pages that have such a context, it is clear to see that classic JSOM can't work in remote webs.
SharePoint 2013, however,provides a workaround utilizing the SP.ProxyWebRequestExecutorFactory that allows you to make cross-domain calls using JSOM. These cross-domain calls are in lieu of using C#, CSOM, and the OAuth plumbing, which is a better choice but may not be possible in all situations. If, for example, you have a remote web that is outside the firewall and needs to call back to an on-premise SharePoint farm, OAuth will not work. In this case, the cross-domain JSOM solves the problem.
Cloud-Hosted, JavaScript, REST
There is also a REST version of the cross-domain library, which accomplishes the same ends. Again, REST is more standard than JSOM, so you should favor this approach.

Impossible Impossible
C# cannot be used in a SharePoint-hosted app in any way because server-side code is not allowed. Period. There is no way around this fact.

Beer Debate Debate Over Beers
SharePoint-Hosted App, JavaScript, JSOM
I've already made the argument that REST is more of a standard than JSOM. However, there are legitimate advantages to using JSOM over REST. The most-important advantage is that JSOM is currently a superset of REST functionality. There are some operations that can't be performed in REST. For example, updating content types and pushing changes to all lists is simple in JSOM, but not supported in REST as far as I can tell (even though the API sort of suggests it is).
The second advanatge of JSOM is that it currently has much better documentation than the REST API. This is because it has been around since 2010. I'm sure the REST documentation will catch up, but right now, it is often frustrating to do anything beyond CRUD operations.
Finally, JSOM payloads are smaller than REST payloads. Some non-scientific Fiddler analysis has shown REST payloads to be as much as 2x JSOM payloads.
Cloud-Hosted, C#, REST
I've already gone over some of the reasons why I think this combination is not a winner. I've listed it here because it is possible so someone may want to debate its merits. However, I think this is pattern is so tedious that I would never use it.

Conclusions
A couple of clear takeaways from this analysis:
·        If you are writing a SharePoint-Hosted app, use JavaScript and the REST API, not JSOM
    unless you are involved with operations not currently supported by REST
·        If you are writing cloud-hosted apps, use C# and the managed version of CSOM, not REST

·        If you are writing a cloud-hosted app and you are trying to call back into an on-premises
    SharePoint farm through a firewall, use JavaScript, REST, and the cross-domain library.

Friday, October 4, 2013

ScriptLink registration in SharePoint 2013 sandbox solution causes blank page

copyright from: http://blog.lekman.com

When publishing a custom action for registering jQuery or another external script via ScriptLink, you might get a blank white page.
<CustomAction
  Id="LoadJQuery" 
  ScriptSrc="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"
  Location="ScriptLink" 
  Sequence="100" />
Sample 1: External script link that will not render correctly
Based on this it will look for a folder called "Scripts" inside of your "15/TEMPLATE/LAYOUTS" folder.  This will only work if the solution is full trust since the sandbox will not have access.
To get around the issue, you must deploy the file to the local SPWeb and reference the file using the relative handler “~site”.
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <CustomAction
    Id="LoadJQuery" 
    ScriptSrc="~site/script/jquery-1_8_3_min.js"
    Location="ScriptLink" 
    Sequence="100" />
  <Module Name="ScriptRegistration">
    <File 
       Path="script\jquery-1_8_3_min.js" 
       Url="script/jquery-1_8_3_min.js" />
  </Module>
</Elements>
Sample 2: Complete elements declaration of internal referenced script link that will render correctly.

Tuesday, September 17, 2013

How To Set Up Wireless Ad Hoc Internet Connection In Windows 8

Copyright from: www.redmondpie.com

Windows 8 isn’t just missing the Start Orb or the ability to easily restart/shut down the PC; there are certain other elements that Microsoft either decided to bury deep within the settings, or omit altogether, when compared with Windows 7 and earlier iterations of the operating system. Among them is also the ability to easily create ad-hoc wireless networks using your current internet connection and wireless adapter. Essentially, an ad-hoc wireless connection turns your PC into a virtual Wi-Fi router, allowing other devices to connect to the internet through a shared internet connection, each with its own unique IP address. Until Windows 7, ad hoc connections were a breeze, since there was an option to create one right in the Network Management utility. With Windows 8, the ability does exist; it’s just a little hard to achieve. In this article, we’ll guide you how to create a wireless ad hoc connection under Windows 8.
The procedure outlined here makes use of Windows’ native Network Shell utility, deploying thewlan command within the utility to enable a hosted network that will, in turn, serve as your ad hoc connection. If all this sounds daunting, fret not, for the actual procedure is fairly easy. Follow the steps outlined below, and you should be good to go.
Windows8AdHoc
It should be noted that for this method to work, your network interface must be capable of supporting hosted networks. It’s always advisable to update your network adapter to the latest drivers before doing this.
Procedure
Step 1: Launch an elevated command prompt under Windows 8 (one with administrator privileges).
Step 2: Run the following command to verify that your network interface supports virtualization:
netsh wlan show drivers
Hosted Network support
If Hosted network supported says Yes, you’re all set. Otherwise, you need to upgrade your hardware, if the software update doesn’t fix it.
Step 3: Now, set up the ad hoc wireless network using this command. Replace the parts in markup tags with your own choices
netsh wlan set hostednetwork mode=allow ssid= key=
image
Step 4: Until now, your hosted network has been created. Now, you need to start it. Use the command below:
netsh wlan start hostednetwork
image
Step 5: You’re all set, with just one thing remaining. If it’s not already enabled, you need to allow Internet Connection Sharing (ICS) for your currently-active internet connection. Simply head over to Network & Sharing Center, and in the properties for the current internet connection, enable ICS. Make sure to select the ad hoc connection under Home networking connection.
Allow ICS


Now you can connect any device to the internet using the ad hoc wireless network with internet connection sharing that you just created on your Windows 8 PC.
Networks
It’s worth noting that this isn’t the only method to create an ad hoc connection. If you don’t want to play around with netsh command, or just need an easier solution, you may simply use a Virtual Router application for Windows, and that should do the trick for you. Google them out, you’ll find various good candidates there.

Monday, September 16, 2013

SP.UI.ModalDialog.showModalDialog(options) in SharePoint 2013

Have you ever tried using SP.UI.ModalDialog.showModalDialog(options) in SharePoint 2013. I discovered some strange behavior…
After migrating my code from SharePoint 2010 to SharePoint 2013 the calls to showModalDialog failed with message that the method cannot be found (javascript). When checking it in IE Developer Tools this isn’t surprising at all. The required js-file isn’t loaded.
But why? I guess it must be the new SOD-Model (Script on Demand) that was introduced in SharePoint 2013.
So I looked for a function that would force to load the missing js. Here it is:
SP.SOD.executeFunc(‘sp.ui.dialog.js’, ‘SP.UI.ModalDialog.showModalDialog’, function () { ShowUploadDialog(); });
With that function you can force IE to load the missing js with the needed method. The last parameter ist a delegate where you can e.g. call a function that uses the function you just ensured to be loaded.
Simple as that…
Notice: I first tried the “executeOrDelayUntilScriptLoaded”-function. But it was not of much help. It just “swallowed” my function call but never executed it because the js-file I specified was never loaded :-(
Hope this helps anyone out there!

SharePoint Internals: Resources

copyright from: tomblog.insomniacminds.com

In a country where English is not the native tongue, localisation can be pretty important. Localisation within SharePoint is achieved by using resources and resource files. Although the use of resources is not mandatory, it’s usually good practise to use them anyway. You don’t want to hard code strings in your application, and, moreover, you never know when your application should be localized. Setting up and using these resources in SharePoint can be quite confusing. So here is a little article covering this topic.
Resources
Resources – in this case: strings – are contained within XML based .resx files. Every resource in such a file is identified by a fixed name. (quite like a HashTable) Here is a little example.


Manage the field of this application.

For every new localization, you need a new .resx file with the same names as keys. You can just copy the original .resx file to achieve this quickly. In this new resource file you translate the original values within the value tag. The new resource file has to be named as follows: ..resx.
eg. – myresource.resx
- myresource.en-US.resx
- myresource.fr-FR.resx
SharePoint & Resources
First thing you need to know, SharePoint defines two kinds of Resource files: Application resources and Provisioning resources. Application resources are resources used within the normal execution of the SharePoint application. Normal SharePoint execution include: Application Pages, Web Parts and Controls. SharePoint also makes a difference between application resources used in normal web applications and application resources used in the central administration. Don’t forget that. Provisioning resources, on the other hand, are used when provisioning elements, so you have to use them within features, site definitions and list definitions. Ok, now let’s see the practical side of it: deployment and usage.
1. Deployment
Resource files in SharePoint are located in different folders. Here is a list:
  • C:\Inetpub\wwwroot\wss\VirtualDirectories\\App_GlobalResources\
  • \12\Resources\
  • \12\CONFIG\Resources\
  • \12\CONFIG\AdminResources\
  • \12\TEMPLATE\FEATURES\\Resources\
So, how do you know where to put your resource files? Well, every type of resource has its own folders.
Provisioning resources
  • \12\TEMPLATE\FEATURES\\Resources\Resources..resx
  • \12\TEMPLATE\FEATURES\\Resources\
  • \12\Resources\
Every feature uses the resources file located in its Resources folder. You can however use another resource file or even share resources. To share resource files you have to put them in the 12\Resources\ folder. Site definitions and list definitions also get their resources from this folder.
Application resources
  • \12\CONFIG\Resources\
  • C:\Inetpub\wwwroot\wss\VirtualDirectories\\App_GlobalResources\
Application resources are located in CONFIG\Resources folder. For a web application to use those resources, they have to be copied to their App_GlobalResources folder. (each web application has its own Global Resources folder) How is this done? At creation of the web application, the resources are initially copied to the App_GlobalResources folder. When adding new resources to the CONFIG\Resources folder, the resources have to be copied to existing web applications. You can do this manually or use the STSADM command: copyappbincontent.
Application resources: admin
  • \12\CONFIG\AdminResources\
  • C:\Inetpub\wwwroot\wss\VirtualDirectories\\App_GlobalResources\
Application resources for the central administration work the same way as normal application resources, except that the base folder is CONFIG\AdminResources.
2. Usage
This last part will focus on how to use resources within SharePoint elements. Luckily it doesn’t really matter which kind of resource you are using. Here are the different ways:
In C#:HttpContext.GetGlobalResourceObject("MyResource", "MyName").ToString();
In ASPX properties:<%$Resources:MyResource, MyName%>
In ASPX as text:
In XML:$Resources:MyResource, MyName
In XML features, using the default resource file:$Resources:MyName
3. Conclusion
There you go. Everything you will ever want to know about resources in SharePoint.
Part of this article is derived from the excellent article of Mikhail Dikov. You can consider this article as some sort of extension of his article. Be sure to read it. Also, I’d like to thank Tom Verhelst for the heads up on the copyappbincontent. Thanks man!
Have a great week!

Sunday, August 11, 2013

How to Dual Boot Windows 8 with Windows 7

copyright from: www.pagestart.com
Your newly purchased computer or the one you just built has Windows 8 installed. You now want to install Windows 7 as a second operating system thus creating a Dual Boot computer and giving you the best of both worlds and full app compatibility as some of your Windows 7 applications may not be supported in a Windows 8 environment.
 
Considerations before you start:
A) If you purchased your Windows 8 computer:
1 - Installing Windows 7 may void your warrantee. Call the PC manufacture and ask !!!
2 - Installing Windows 7 may render your Windows 8 “Recovery Partition” useless. Before you start, contact the PC manufacture and obtain the “Recovery media” for Windows 8. Also ask the manufacture’s support team about activation when using recovery media as your new computer may no longer have a product key code sticker, Windows 8 uses a BIOS imbedded product key for activation.
 
Partition arrangements on a computer purchased with Windows 8 may vary from manufacture to manufacture. For example a Dell computer could typically have a large number of predefined partitions:
 
EFI System Partition - 500 MB
OEM Partition - 40 MB
Recovery Partition - 500 MB
Recovery Partition - 10.63 GB
Boot, Page File, Crash Dump, Primary Partition 919.74 (Windows 8 OS C:)
 
New computers come with a feature called “Secure Boot”. You may need to temporarily disable secure boot in the BIOS before you can install Windows 7. Check your owner’s manual or contact your PC manufacture’s support team for help on how to do this.
 
3 - Are there Windows 7 device drivers for your computer’s make and model available from the manufacture’s driver support download web site? If there are no Windows 7 device drivers then installing Windows 7 may be a waste of time as your Display, Touch pad, Camera, USB and other devices may not function properly.
 
B) If you have built your own computer:
1) Verify there Windows 7 device drivers for your motherboard’s make and model available from the manufacture’s driver support download site. There is a good chance there are Windows 7 drivers and in fact less of a chance there are a full set Windows 8 drivers for older motherboards. More recently released boards will support XP, Vista, Windows 7 and Windows 8. The assumption however is that you already have Windows 8 installed as your first operating system on the disk drive.
 
Conceptual overview:
1) This article is based on a home built computer using a 1TB hard drive.
2) The free version of EaseUS Todo Backup will be used to create an image backup of the drive to an external USB drive before starting. Todo supports both Windows 7 and Windows 8.
3) You need to shrink the Windows 8 partition to make room for a Windows 7 partition. For this task you will use Windows 8’s ‘Disk Management’. To access Disk Management, open the ‘Desktop’ and press the Windows key + X, then select ‘Disk Management’.
4) You will need to disable Windows 8’s ‘Fast Startup’ option before you install Windows 7.
Why disable ‘Fast Startup’:
Failure to disable the fast startup option can result in ‘Check Disk’ (chkdsk) running when installing Windows 7. You may also no longer see the dual boot menu the next time you turn on your computer. Also if you have more than 1 disk drive chkdsk will run each time you shut down from within Windows 8 and then boot to Windows 7.
 
Fast Startup in Windows 8 is designed to close and reopen by fast booting (Hybrid Boot), it has left your system in a partially hibernated state, with the drive mounted and according to Microsoft "effectively saving the system state and memory contents to a file on disk (hiberfil.sys) and then reading that back in on resume and restoring contents back to memory."
 
Turning off the “fast startup/hybrid boot” option fixes the chkdsk problem during the installation of Windows 7, the missing boot menu problem (more on this later) and the multiple disk drives “Dirty bit” issue when booting to Windows 7.Windows 8 may take little longer to boot but not all that much as to be meaningful. Boot times for Windows 7 are unaffected and the boot menu will be displayed each time you turn on or reboot the computer.
 
How to disable ‘Fast Boot’:
Make the following changes to the Windows 8 Power Options.
1. Control Panel --> View by: Small Icons -->Power Options
2. Select "Choose what the power button does" on left hand side.
3. Click on "Change settings that are currently unavailable".
4. Uncheck "Turn on fast startup" under shutdown settings.
5. Click on the ‘Save changes’ button.
Create an Image Backup:
Before you make any changes to your Windows 8 computer, create an image backup. Its your safety net should something go wrong. I used the free version of EaseUS’s Todo Backup and an external USB drive to store the image file.
EaseUS Todo Backup: http://www.todo-backup.com/products/home/free-backup-software.htm
 
Note: The Image should include “All” partitions on your disk drive. Therefore use the Disk and Partition backup option and not the ‘System Backup’ option. Click on the left edge of the image of the disk’s partition map to select the entire drive (this will highlight the entire drive in a golden box. Change the destination to your USB drive. Note: You can create a unique destination and folder name for each backup you create by clicking on the File Explore (formerly called “Windows Explorer”).
 
Using Disk Management to create a partition for Windows 7:
1) Open Windows 8’s ‘Disk Management’ (press and hold the ‘Windows’ key and tap the X key). Then select the ‘Disk Management’ (or tap the ‘K’ key) option from the list.
2) Change the ‘Volume name’ to “Windows 8 Pro” (Without the quotes). Right click on the Windows 8 partition (C:) and select ‘Properties’. In the ‘General’ tab change the existing name to: Windows 8 Pro and click the ‘Apply’ button.
3) Shrink the Windows 8 partition to create unallocated space for use when installing Windows 7. Right click on the Windows 8 partition (C:) and select the ‘Shrink Volume’ option. Now enter a value for the amount of space to shrink in MB. For the 931GB partition in this example I wanted to create a 460GB partition for Windows 7, so I entered a value of 471040 (460 X 1024). If your Windows 8 partition contains a lot of data you want to consider a smaller partition size for Windows 7 (75 to 100GB).
Click the ‘Shrink’ button to start the process. After the shrink operation has completed you will see 460.00GB in “Unallocated” space.
4) Create a “Primary” partition and format it. Right click on the unallocated space and select ‘New Simple Volume’.
In the “Format Partition” window you want an ‘NTFS’ partition, leave the allocation unit size set to ‘Default’ and either choose a ‘Quick’ or ‘Full’ format. I prefer a full format (takes longer to complete, but it’s safer) so as the screenshot below shows, the ‘Perform a quick format’ option is unchecked. Click ‘Next’ to continue.
5) Change the volume name to Windows 7 (or Windows 7 Pro or Windows 7 Ult if Home Premium is not what you are installing). This will make it easy for you to select the proper location on the drive during the Windows 7 installation process.
6) At this point I created another Image Backup of the drive (all partitions) using Todo Backup. This allows me or you to return to the current state should Windows 7 fail to install properly the first time around.
 
7) You are now ready to install Windows 7. This will be a “Keyless” install, should anything go wrong your Windows 7 product key will not have been used or activated and you can try again.
 
For reference purposes a “Keyless” install simply means you will skip entering in a product key during the install and activate Windows 7 at a later point in time. More on this subject later.
 
I’m not going to show you screenshots for each step in the installation of Windows 7 as this has been documented many times.
 
What I will provide is the basic information and screenshots at key points in the installation process that you will need to know and follow.

Monday, July 22, 2013

SharePoint 2013 – Oh wherefore art thou Blank Site Template

Copyright from: itproafrica.com/technology/

Blankman this one’s for you :)
Just because it’s about the Blank site template.
If you upgrading or just looking to create a blank site in SharePoint 2013 you will notice its not there by default.
Have no fear for it still exists in the web template gallery.
To have this activated on you site.
* Browse to : C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\TEMPLATE\1033\XML* Edit file : WEBTEMP.XML
* Locate this line of code :
Not really :P
* You will see the blank site when you create a site collection via CA
* But not when you create a site in that site collection or subsite
* To activate for sites or sub sites
* Browse to your site
* Browse to site settings
* Under look and feel select Page layouts and site templates
* Under the sub site templates select Blank Site all and add it to the window on the right
Now you are done
Happy Blank site creation