Scenario:
Opened an old silverlight project and got following error.
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found. Confirm that the path in the <import> declaration is correct, and that the file exists on disk.
Solution:
1. Download Silverlight4_Tools from MS Web site and install it
2. Close VS 2010 and start again to load the project
Wednesday, November 16, 2011
Monday, August 9, 2010
Scenario:
Silverlight and SharePoint 2010 is great combination. Here's a quick post of how to pass parameters to Silverlight and consume them in Silverlight.
Solution #1: (Initialization Parameters)
This is most commonly used way to pass the values. This is how we declare it.
ASPX(C#)
<asp:Silverlight ID="Xaml1" runat="server"HTML
Source="~/ClientBin/InitParamsMgr.xap"
MinimumVersion="2.0.31005.0" Width="100%" Height="100%"
InitParameters="param1=value1,param2=value2">
</asp:silverlight>
<object id="SilverlightPlugin1" width="300" height="300"How to use it in Silverlight:
data="data:application/x-silverlight-2,"
type="application/x-silverlight-2" >
<param name="source" value="SilverlightApplication1.xap"/>
<param name="InitParams" value="param1=value1,param2=value2" />
<!-- Display installation image. -->
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50401.0"
style="text-decoration: none;">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376"
alt="Get Microsoft Silverlight"
style="border-style: none"/>
</a>
</object>
1. Add the following code Application_Startup method.
private void Application_Startup(object sender, StartupEventArgs e)2. Open MainPage.xaml.cs and add the following method
{
if (e.InitParams != null)
{
foreach (var item in e.InitParams)
{
this.Resources.Add(item.Key, Uri.UnescapeDataString(item.Value)); }
}
this.RootVisual = new MainPage();
}
private string GetParam(string p)3. Use the following code to read the parameter value
{
if (App.Current.Resources[p] != null)
return App.Current.Resources[p].ToString();
else return string.Empty;
}
string param1value = GetParam("param1");Solution #2: ( Query Parameters )How to use it in Silverlight:
1. Add the following code Application_Startup method.
private void Application_Startup( object sender, StartupEventArgs e ){
this.RootVisual = new MainPage();
string queryParam = HtmlPage.Document.QueryString["key"];
this.Resources.Add( <resourcekey>, queryParam );
} 2. Use the following code to read the parameter valuein XAML
<silverlightcontrol property={StaticResource ResourceKey} />or in C#object parameter = ((App)Application.Current).Resources[<Resourcekey>];
Article:
How to pass initialize parameters..
Related and Referred Articles:
MSDN
Decoding paramters
Scenario:
Client Object Model and Silverlight is best combo which I use often and always get this question on how to get the Current SharePoint Web Url from within Silverlight without passing it from initparam's manually.
Answer is simple
Steps:
1. Open App.xaml.cs and add the following using statements to the top of the file
using Microsoft.SharePoint.Client;2. Add the following code to the beginning of the Application_Startup method.
using System.Threading;
ApplicationContext.Init(e.InitParams, SynchronizationContext.Current);3. Open MainPage.xaml.cs and add the following using statement to the top of the file
using Microsoft.SharePoint.Client;4. Use the following code to get the client context for current web
ClientContext context = new ClientContext(ApplicationContext.Current.Url);
context.Load(context.Web);
List listSharedDocuments = context.Web.Lists.GetByTitle("Shared Documents");
context.Load(listSharedDocuments);
Monday, June 7, 2010
Scenario:
I was trying new features of Silverlight 4 and got following error opening the project
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\Silverlight\v4.0\Microsoft.Silverlight.CSharp.targets" was not found.
Confirm that the path in the declaration is correct, and that the file exists on disk.
Solution:
Reason is simple Visual Studio 2010 is missing the support for Silverlight 4, so you will need Silverlight 4 for VS 2010 to be able to make it work
1. Google for 'Web Installer 2.0'
2. Download and install it.
3. Now launch the Web Installer and look for Silverlight 4 add-on for Visual Studio 2010.
4. Select it and install it.
Just in case Web Installer is not able to install the component or you want to download the Silverlight 4 tools for VS 2010. You can get it from this here
Thursday, May 27, 2010
Scenario:
Wrote a small Silverlight application which was trying to display the title of the site using Client Object Model and to my surprise I got the following error :
{System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.BrowserHttpWebRequest.<>c__DisplayClass5.
at System.Net.AsyncHelper.<>c__DisplayClass2.
--- End of inner exception stack trace ---
at System.Net.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)}
Solution:
This can be because of few reasons
1. Make sure the web URL used to create the Client context object exist and brows-able.
2. This might be because of missing client policy access file missing for the SharePoint Web Application not allowing you to connect. Create a new XML file named ClientAccessPolicy.xml with content below and save it to 'C:\inetpub\wwwroot\VirtualDirectories\80'
Note : Update policy file and port number as needed.
ClientAccessPolicy.xml:<?xml version="1.0" encoding="utf-8" ?>
Once you have the file copied to right location, do an IISReset and make sure you can access the file using following url :
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="*">
<domain uri="*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true" />
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
http://servername:portno/clientaccesspolicy.xml
Note
This setting is only for Development Environment. Read the following article how to tweak the policy file for production environment.
Article:MSDN
Scenario:
I build up a new VM and was experimenting with Silverlight and SharePoint. I created a new Silverlight Application Project in Visual Studio. Then I tried adding the client object model dlls.
Microsoft.SharePoint.Client.Silverlight.dll
and
Microsoft.SharePoint.Client.Silverlight.Runtime.dll
located at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin" and surprisingly got this
Sometime your project build just fine but you get referencing error at run time, something like this.
Solution:
Two step solution was
1. Copy both the binaries from
"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\ClientBin" to "C:\SilverlightClientOM" folder.
2. Reference from the new folder
Wednesday, July 30, 2008
Microsoft Silverlight is a cross-browser, cross-platform, and cross-device plug-in for delivering the next generation of .NET based media experiences and rich interactive applications for the Web. Silverlight offers a flexible programming model that supports AJAX, VB, C#, IronPython, and IronRuby, and integrates with existing Web applications. By using Expression Studio and Visual Studio, designers and developers can collaborate more effectively using the skills they have today to light up the Web of tomorrow. By leveraging Silverlight's support for .NET, High Definition video, cost-effective advanced streaming, unparalleled high-resolution interactivity with Deep Zoom technology, and controls, businesses can reach out to new markets across the Web, desktop, and devices.



