RSS
 

Silverlight 4 Childwindow is not visible

03 Aug

When you already have some XAML code and you want to show a ChildWindow afterwards, it can be that the ChildWindow is not displayed. Normally everything should work out of the box when you start a new project and try it out in the constructor of your XAML page.

However, I found a small fix if you encounter this problem. The following code ensures that the page is fully loaded (using the Loaded Event) before we show our Child Window.

        public Page()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Page_Loaded);
        }

        void Page_Loaded(object sender, RoutedEventArgs e)
        {
                ChildWindow cw = new LoginForm(this);
                cw.Show();
        }
 
 

Application manifest generation failed. The out-of-browser settings file was not specified

29 Jul

Error Message: Application manifest generation failed. The out-of-browser settings file was not specified

That error can popup in visual studio if you try to enable the OOB capabilities of silverlight. It has probably to do with Team Foundation Server or reading rights on certain files.

For some reason the *.csproj isn’t updated. You need to manually add the following line:

Under:

Add the following:

Properties\OutOfBrowserSettings.xml

Make sure you can see the OutOfBrowserSettings.xml in your visual studio project under the Properties folder. Otherwise Show all files and include the file in the project.

That should fix it!

 

Forms Based Authentication in SharePoint 2010

24 Apr

The FBA in SharePoint 2010 is basically the same process as you should configure FBA in SharePoint 2007…

This post assumes you have already created your Content Website.

These are the screenshots (ordered from left to right):

After you completed screenshot 1-4, change Web.Config of your content website to be able to login.
Add the following between the tags.

  

			  
		  
	  
	  

			  
		  
	  
  
	
		
	

In order to be able to add a collection administrator for your application (Screenshot 6) using FBA you need to update the web.config of your Central Administration website. If it still doesn’t find your user, you should check the eventviewer and your database permissions (make sure SharePoint can access the specified Forms Authentication tables.


  

		  
	  
  
  

		  
	  
  

  
  
  
  

The only thing that is different from your content website web.config change is:

That should make it work!

 

Running 64 bit virtual machines

30 Mar

If you want to install the latest technologies of Microsoft (like Microsoft Office SharePoint 2010) you will need to have a 64 bit machine to install everything. The problem is that you want to run a guest virtual machine for development on your 64 bit host. Virtual PC does not run any 64-bit machines, so we need to choose an alternative. After some research, I found Virtualbox from Sun.

VirtualBox is a powerful x86 and AMD64/Intel64 virtualization product for enterprise as well as home use. Not only is VirtualBox an extremely feature rich, high performance product for enterprise customers, it is also the only professional solution that is freely available as Open Source Software under the terms of the GNU General Public License (GPL).

The complete supported list of OS is here:
http://www.virtualbox.org/wiki/VBox_vs_Others

Everything works very smooth and it even seems faster than my current Virtual PC (or is it because I am using the W2k8 R2 now… :) )

 
 

Virtual PC could not connect to the internet

28 Feb

I am pretty excited about my traning class of next week. Architecturing WPF Applications with Brian Noyes from IDesign! While I was setting up my Virtual Machine (Windows Server 2008), I wasn’t able to connect to the internet from my VPC at home. It used to work before at a different location…

My current VPC setting to connect to the internet is setup to use NAT (Shared Networking).

When I looked up my IP Configuration, I had the following result:

The default gateway had been assigned by my VPC and that was probably missing in my Network configuration.

So, basically, you just need to put this setting and everything will work again!

Update:
I found an interesting article about this:
Fix Virtual PC 2007 Shared Networking (NAT) Internet Not Working in Windows Server 2003, 2008 and Vista Guest OS

The problem is that Shared Networking configures the guest operating system to use the same DNS servers as are used by the physical computer. However, when actual DNS query resolving packets are been returned, it’s actually returned from the IP address of “192.168.131.254″, which is the virtual gateway used by Shared Networking (NAT).

 
 

RoleService not working

05 Feb

The WCF Authentication Service is great to use and it works perfectly… however, I had a lot of problems trying to get the roleservice working.

WCF Role Service is not returning any results. Anything is well configured as described on MSDN: How to: Enable the WCF Authentication Service.

I could call the role service without a problem but there weren’t any queries launched at the database.
After a long search on the internet and msdn, I finally found a small MSDN Note that says the following.

Do not call the GetRolesForCurrentUser method from code that is executing on the Web server. You call the GetRolesForCurrentUser method only as part of a WCF service. For more information about how to read a user’s roles in code that is executing on the Web server, see the GetRolesForUser method.

Why I’m using the roleservice from my ASP.Net application is hard to explain… it’s related to the fact that silverlight, sharepoint login form and custom asp.net websites are using the same webservice. We want to limit the configuration of the Membership and have our forms based user object at WCF level.

So when you’re calling this service from a client application (Silverlight), it will work. If you’re calling this from a server application like ASP.Net, you just don’t get any results back… You should use the Membership classes on your custom WCF Service in order to write your own role methods.

 

Write SQL Database size to text file using stored procedure

10 Jan

I had to write a stored procedure that writes the current database size to a text file on a shared network location. We also need to do this each month, but we’ll use SQL Jobs for that… I didn’t find any good solutions on the net so I will share this one!

Now let’s get to the stored procedure code.

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        CODit
-- Create date: 05/01/2010
-- Version: 1.1
-- Description:   Calculate Database Size and write to a file
-- =============================================
CREATE PROCEDURE [dbo].[qry_spaceused_toFile]
 @FullFolderPath varchar(255),
 @DatabaseName varchar(255),
 @SQLServerName varchar(255)
AS
BEGIN
declare @myDate varchar(255),
@QueryString varchar(4000),
@QueryString2 varchar(4000)

Select @myDate = convert(varchar, getdate(), 2)
Select @FullFolderPath = @FullFolderPath + @SQLServerName + '--' + @myDate + '.txt'
Select @QueryString = 'sqlcmd -S"'+@SQLServerName+'" -E -d '+@DatabaseName+' -Q"execute sp_spaceused" >>"'+@FullFolderPath+'" -s"" '
Select @QueryString2 = 'type "'+@FullFolderPath+'"'
create table #errorlog(line varchar(2000))
execute master.dbo.xp_cmdshell @QueryString

insert into #errorlog 

execute master.dbo.xp_cmdshell @QueryString2

Select @QueryString = 'sqlcmd -S"'+@SQLServerName+'" -E -d '+@DatabaseName+' -Q"print CHAR(13)" >>"'+@FullFolderPath+'" -s"" '
execute master.dbo.xp_cmdshell @QueryString
execute master.dbo.xp_cmdshell @QueryString

select line from #errorlog

drop table #errorlog
END

Usage (Make sure your path folder already exists):

exec qry_spaceused_toFile 'PathToFileLocation', 'DataBase', 'SQLServerName'

Possible Output:

database_name database_size unallocated space
————————————————————
CIPPlatform 6.75 MB 0.81 MB

reserved data index_size unused
————————————————————————
3264 KB 1712 KB 1288 KB 264 KB

Explanation:

We are using the sqlcmd to write to a text file. This has some limitations, but it’s fine to use in our situation. I didn’t find any easy method to write to a file using sql. If you want to learn more about the sqlcmd utility, I suggest you to read this tutorial. As the name states, sqlCMD, you normally use this command in a command prompt. However, you can use it in SQL by using the master.dbo.xp_cmdshell procedure!

We are using the built-in system query ‘sp_spaceused’ to calculate the space. After executing, you’ll see two resultsets. In order to write those 2 resultsets to a file we write the results to a temporary table and write the contents that are stored in the table. The output file name is a concatenation of the database name and date.

 

Silverlight ClientConfig File Injection

10 Jan

Although it was fun to create this one. Jermemy Likness wrote a nice article about constructing your service configuration dynamically. It’s an easy solution that I saw too late! You can find it in detail here: http://csharperimage.jeremylikness.com/2009/07/abstracting-wcf-service-calls-in.html

For development, you are probably pointing to your localhost when you need to call your webservices. When you have a scenario where you are not sure about the endpoint service URLs of your silverlight application, you need to change the ServiceReferences.ClientConfig file manually (or make it configurable in code, but we don’t know the URLs anyways…) after it has been packaged in a XAP file. Also if you’re working with HTTPS in silverlight, you need to change the ClientConfig file in order to work with Transport Security. If you have to deploy your XAP file to a lot of machines (or just a lot of times) you always need to perform 6 steps:

  • Rename your XAP file to zip
  • Extract the zip file to a folder
  • Edit the ServiceReferences.ClientConfig
  • Add the folder contents to a zip file
  • Paste the ZIP file in the ClientConfig folder and delete your old one
  • Rename the zip file to XAP

To avoid those steps, I made a little WPF application. It can perform all of these steps for you. You can also run it from the command line so you can automate everything (just a change in your clientconfig to point to the right service is required).

This is the application when you double click the EXE file.
Startup Screen (GUI Mode)

You can drag and drop your files in the window to load your XAP and/or ServiceReferences.ClientConfig file. If you do not specify a ClientConfig, you need to paste your config text in the textbox. The application will automatically pick it up and inject a new ServiceReferences.ClientConfig file for you. By default the application will backup your old XAP file. If there is already a backup, it will add an increasing value before the extension.

You can also use the application in Command Line Mode. To begin, just browse to your folder and enter ServiceInjection.exe -h. You’ll see the following output:
Commandline options

A sample of a commandline execution in a batch file would be (files are in the same folder):

CD “C:\ServiceInjection\”
ServiceInjection.exe -x \MySuperSilverligtFile.xap -s \ServiceReferences.ClientConfig -b true

You can specify a full path if your files are not in the same folder:

CD “C:\ServiceInjection\”
ServiceInjection.exe -x “C:\XapFiles\MySuperSilverligtFile.xap” -s “C:\ServiceFiles\DeploymentServer1\ServiceReferences.ClientConfig” -b true

Download the application single executable:
ServiceInjection Application

Download the source project (make changes as you wish to fit your needs):
ServiceInjection Program Source

 
 

Drag and Drop of files in WPF

10 Jan

Dragging and Dropping files in a WPF application isn’t hard. The only thing you need to do is to set the AllowDrop property to true for the whole window. Add a window drop event and everything is set… except when you’re adding extra controls like a textbox for instance. When you’re dropping files to a textbox, the drag and drop won’t work. In order to make it work you need to set the following on your textbox.


public void OnDragOver(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.All;
e.Handled = true;
}

That should do the trick!

 
No Comments

Posted in WPF

 

Silverlight DataGrid and DataPaging (frozen datagrid problem)

14 Dec

There are a lot of resources on the net where you can find datapaging using RIA Services. But what if you don’t want to bind to a DomainDataSource. You only want to bind to your collection and add DataPaging to your grid.

It’s fairly easy as you can read on MSDN

You just need to bind your datagrid to a PagedCollectionView.

The reason why I’m posting this is because I had trouble with my datagrid once it has been datapaged. The datagrid was frozen, I couldn’t sort, I couldn’t reorder my datagrid columns and I even couldn’t make a selection. You should make sure that your controls are on different rows in your grid.