Back Home to start page Buy ASP.NET 2.0 book from Hannes PreishuberBlog from Hannes Preishuber (weblogs.asp.net) Speeches Slides Demos
Code Samples zum Buch ASP.NET 2.0 Crash Kurs



 

Blog from Hannes Preishuber original located on weblogs.asp.net/hpreishuber

Sun, 24 Aug 2008 06:05:26 GMT - Silverlight 2.0 plugin ID or not ID


My original problem was a call from HTMl via Jscript to the internals of a Silverlight plugin. My code fails I had huge problems to find the issue cause debugging doesn’t help and jScript doesnt support intellisense i a complete matter.

My checklist

1) Silverlight 1.0 uses a findname construct, Silverlight 2.0 the xaml class must expose a <Scriptable> member and it must be registered with RegisterScriptObject

HtmlPage.RegisterScriptableObject(

"hannespre", Me)

2) The Call by Jscript from a Silverlight event method like loaded, have a sender object as parameter. On that you can use getHost to get a instance of Silverlight host.

If you call without, like a hmtl button click, you have to find the the Silverlight plugin.

var slhost = document.getElementById("sl1");

3) ASPX or HTML. Silverlight projects in Visual Studio 2008 creates a additional web project. This have to test pages. A html and a aspx.

ASPX

<asp:Silverlight ID="SilverlightControl"

PluginBackground=Transparent

runat="server" HtmlAccess=Enabled

Source="~/ClientBin/SilverlightApplication1test.xap"

MinimumVersion="2.0.30812" Width="100%" Height="600"

/>

HTML

<

object data="data:application/x-silverlight," id="sl1"

type="application/x-silverlight-2" width="600px" height="400px">

<param name="source" value="ClientBin/SilverlightApplication1test.xap"/>

<param name="onerror" value="onSilverlightError" />

<param name="background" value="white" />

<a href="http://go.microsoft.com/fwlink/?LinkID=115261" style="text-decoration: none;">

<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/>

</a>

</object>

The ID of the Silverlight Plugin is set with the ID attribute. There are different default values in ASPX and HTML (XAML1). If you miss the ID, Silverlight will work.

4) you can read the created plugin id during runtime

 Private Sub page8_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        HtmlPage.RegisterScriptableObject("hannespre", Me)
        label1.Text = HtmlPage.Plugin.Id
End Sub

 

5) From HTML following code access Plugin

function Button1_onclick()

{

var slhost = document.getElementById("sl1");

slhost.content.hannespre.interntext(

"geht");

}

6) take care on pressing F5 and starting debugging. Can start HTMl or ASPX page (and your code is in other page)

Mon, 11 Aug 2008 05:40:29 GMT - Bind with Expression Blend: cannot create Instance Exception


Databinding with XAML is a lot of work. There is no drag drop table wizard, don’t search for it. Expression Blend (2.5) have a little bit more automatic support for binding Objects. When Blend is in Design View there is under Project tab a Data tab.

Step1: open + CLR Object option- then you get a error message “loading assembly” which can be ignored (what else?)

image

image In the next dialog the class have to be selected which returns the data.

In my case I got 100 times an error in Blend. The exception says nothing for me.

image

Step 2: Debugging

Expression Blend tries to create a instance of my object during design time. That's a risk cause many parameters can differ to run time like, connections string, database, path and so one.

First there must be some split between design and runtime code. There is a trick to do that. If no htmlpage is present, the container must be something else. Till now a usual container of silverlight xap applications is a browser (and nothing else)

Public Sub New()

' für Blend Designmode

If HtmlPage.IsEnabled = False Then

'dummydaten mit vollem pfad

Dim myxml = XDocument.Load("northwind.xml")

In this container is Blend. Then attach the Blend process to visual studio debugger. For that visual stuido must be open and the project must be compiled. Take Blend for compiling makes it a little bit easier for me. Dont forget to set breakpoint into your constructor.

image

In my case the code failes on the load place. The reason is ( now I know it) that i have added the XML file as content to my xap packet. But there is no xap package for blend.

The solution is to include the xml as resource into the assembly and load the xml with following code

Dim myxml = XDocument.Load("/databindingvb;component/northwindblend.xml")

Hope this will save you some hour.

Thu, 31 Jul 2008 08:54:17 GMT - set as start page: Silverlight XAML


I really miss the option “set as start page” in Visual Studio Explorer for Silverlight Projects. If I have time in the next days (;-))Ii will write visual studio extension for that purpose.

In fact it is not complicated. The app.xaml have a codebehind file ( app.xaml.vb or app.xaml.cs) which create a instance of the visible XAML. Btw that is the reason for changing xaml to usercontrol in B2.

All you have to to, to change the start page is to change one line of code in startup. Instead of page write the name of the class you want to show.

Private Sub Application_Startup(ByVal o As Object, ByVal e As StartupEventArgs) Handles Me.Startup
        Me.RootVisual = New secondXAML()
End Sub

Tue, 29 Jul 2008 18:32:00 GMT - fast and furios Silverlight Databinding with Gridview and embedded XML Data Resources


 

I am currently writing a Silverlight 2.0 course. I always try to focus on the problem and reduce the code overhead. For my Module “Databinding with Silverlight 2.0” I try to include the data as raw xml. For that purpose I include a northwind.xml file as data source into the project to focus on datagrid details. The most important part is, to set the build action to content, which ends up in including the xml file into the xap package.

 image

Then you can load the xml directly by xdocument.load. I had problems when xml is not valif or have exoctic encoding ( windows-1252). Rest is a little bit LINQ to create collection of northwinddata objects.

 

 
 Dim myxml = XDocument.Load("northwind.xml")
 Dim xmlquery1 = From x In myxml.Descendants("row") _
               Select New northwinddata With _
               {.customerid = x.@CustomerID, _
                .companyname = x.@CompanyName}
 dataGrid1.ItemsSource = xmlquery1

 

Finally the result

image

Interesting note at the bottom line. It is also possible to load the xaml content.

 Dim myxml  XDocument.Load("/gird1;component/page.xaml")

Mon, 21 Jul 2008 12:22:13 GMT - IE 8 simultaneous connections changed


Small note. The Internet Explorer 8 have increased the amount of connections to the same domain to 6. ( was before 2)

Can have some effects in AJAX callbacks, like Web Service calls.

 

http://msdn.microsoft.com/en-us/library/cc304135(VS.85).aspx

Thu, 17 Jul 2008 17:50:00 GMT - reverse engineering of Silverlight XAP files


 

In my last post Michael Schwarz noticed  that search engine spiders can theoretically  index xap files.

Silverlight 2.0 creates a xap file where dll’s, images, videos and xml are included.

First step is to search in web for files with xap extension and download it. Then uncompress it with unzip algorithm ( eg rename to zip).

You will find a dll with the logic inside and several dll’s with librarys and a manifest file.

image

The you ca use (good old) reflector to disassemble the dll. The most interesting fact is that the original XAML file is included as resource.

image

You can then export ( save) the silder.xaml and open it with eg Expression Blend. Logic can be also taken from reflector which have the option to show it in VB.NET or C#.

Back to my beginning point. Till now I don’t know any search indexer which will do that.

Mon, 23 Jun 2008 19:13:13 GMT - What I miss in Silverlight 2.0


No, I do not miss a particular control or class. I am thinking about principle design issues.

Search Engines

The extension for Silverlight applications is xap.  The content is kind of binary. At the end of the line, no content for search engine spider.

Proposed solution: add metacontent, like the original XAML file.

Librarys

Some of the new controls are not included native in Silverlight base installation. Datagrid or Tabcontrol are in separate dll’s (e.g. System.Windows.Controls.Extended.dll). If such control’s or functionality like linq is used, project needs reference to one ore more additional DLL’s. That increase xap size between 100-200K per dll. Second issue is, that code is not cached localy. I would move library code to silverlight addin or add caching. 

run local

I see no reason why xap code must run within a HTML page. As Silverlight is a host for xap it should be possible to install that host for xap in OS.

Wed, 18 Jun 2008 06:37:48 GMT - fixed: asp.net gridview dataformatstring


A old problem was in VS 2005 and ASP.NET 2.0 that you have to set htmlencode=false to enable the dataformatstring.

Since SP1 of VS 2005 ( and ASP.NET 2.0 ) there is a new property in town HTMLEncodeFormatString which have default value false. So it is not necessary to set the value of the attribute.

<asp:BoundField DataField="RequiredDate" DataFormatString="{0:d}"

HeaderText="RequiredDate" SortExpression="RequiredDate" />

image

Thu, 05 Jun 2008 05:57:50 GMT - what I miss in LINQdatasource


ASP.NET SQLDatasource control was for me a super productive tool in the past. There are some small features missing like a more elegant data paging. ASP.NET 3.5 bring a new control LinqDatasource which have great support for data paging. So I tried  to create a rss feed with LINQtoSQL and LinqDatasource. Result is not as I expected.

Caching

SQLDatasource supports data Caching with simply two attributes enablecaching=true and cacheduration=60. Caching makes applications much faster.

Filtering

In combination with  caching SQLDatasource supports filterparameter which allow a kind of offline (from database) filtering. Also makes application faster and reduce load on SQL server.

FilterExpression="ProductName LIKE '@PN%'"

extended where conditions

As in the sample before i miss extended where condition in LINQ querys. The wizzard of LINQdatasource only allow a few expressions like ==.

In pure LINQ querys you can use syntax like

Dim expr = From hannes In kunden.Kundens _
                   Where hannes.City Like "a*" _
                    Select hannes

or even

 Where SqlMethods.Like(hannes.City, "a%") _

Both doesn’t work in LINQdatasource.

Relations

For this point i am not sure if I miss some part. With sqldatasource I usually join data via SQL command. With LINqtoSQL you can define relations but not to handle it virtual as one “table” . With LINQ query's in code that's not a issue. LINQDatasource only allows to select one table so i can not handle the join of normalized data.

 

I am open for discussion at this point.

Fri, 09 May 2008 14:40:35 GMT - want to be a .NET star **{*}**?


you can not sing -

you are running slow-

you are not rich -

you haven't invented the wheel ?

perhaps you a good coder? we are looking for our German and Austrian sub's for upcoming .NET star's.  Several MVP's, authors and speakers come from us. If you want attend the star way, take a look at our web site.

sternelogo_sg

Wed, 30 Apr 2008 18:30:33 GMT - Visendo SMTP (pop3) Extender for Windows 2008 Server


We are migrating some web server from ppedv to windows 2008. IIS 7 is a great improvement. But as always in live, nothing is perfect and we miss the pop3 server from windows 2003.

Our software "visendo" department  have build several products around pop3 (popconnect) and smtp. So we build an extender for IIS Microsoft SMTP server. So you can now use pop3 client to read mails. The solution consists of a filesystem watcher which is moving from drop to other folder(s) fitting the destination address. We support domain and single account (more than windows 2003). Configuration is done with xml. config file by notepad. Visendo SMTP Extender is developed as service with c++ for performance reasons.

On bottom you find links for download first prototype. Support by blog comments. We will open up a support group on our www.visendo.com forums. At the moment product is free an without any warranty.

btw SMTP management is still no part of iis 7 so management is done by old mmc snap in.

[UPDATE]

x64 and x32 editons with minor changes

http://www.visendo.com/download/visendosmtpextender/VisendoSMTPExtender_x64.msi

http://www.visendo.com/download/visendosmtpextender/VisendoSMTPExtender_x86.msi

 

Tue, 29 Apr 2008 06:25:53 GMT - Visual Studio IIS 7 and WebDAV


Visual Studio 2008 have still no native WebDAV support. On the other hand Microsoft is stopping Frontpage Server Extensions development. Both of this web publishing protocols are *not* implemented in IIS7 standard installation. You can download the fitting modules on the iis7 website. If you decide to use WebDAV you have to do following configuration steps

1) Download (X86)

2) installation

3) Enable WebDAV on Site level

4) Enable Authentication BASIC

5) create WebDAV authoring rule which allows read, write for specific user

Steps are described with screenshots here

For visual studio you have to map a file share like

net use z: http://www.fileserver.de

The explorer redirector (which is included since win 2000) only accepts

a) windows authentication or

b) Basic authentication over https =ssl

For resources on the web we have to go way b).

We have to created and assign a certificate to the website on our iis 7. The self signed certificates of iis 7 have no possibility to change the domain name. So default name is always machine name. For solving that I decided to use selfssl from iis6 resource kit. You can install it on windows 2008.

Following code on command line creates an assign the certificate.

selfssl /n:CN=www.fileserver.de /v:1999 /s:1
Microsoft (R) SelfSSL Version 1.0
Copyright (C) 2003 Microsoft Corporation. All rights reserved.

Do you want to replace the SSL settings for site 1 (Y/N)?y
The self signed certificate was successfully assigned to site 1.

Ensure that the SLL binding is enabled in IIS7 site.

Then i opened the website over https   in browser ( Admin mode with uac)and installed the certificate in trustworthy root authority store of client machine. After that following on command line should work on client

net use z: https://www.fileserver.de
Geben Sie den Benutzernamen für "www.fileserver.de
" ein: Username
Geben Sie das Kennwort für "
www.fileserver.de
" ein:
Der Befehl wurde erfolgreich ausgeführt.

Then you should see in Vista explorer

image

Wed, 09 Apr 2008 09:08:44 GMT - 360° Visual Studio 2008, where we are?


I attended as speaker the Bigdays Austria. My session was 360° Visual Studio which I made with Max Knor from Microsoft. Our goal was to give in 70 minutes a complete overview and to code five samples  which have a story line. In sum we had ~1000 attendees in our session. Bigdays is a kind of roadshow in four cities.

Story: new community for developers. Key points: Photo, name, preferedlanguages stored in XML file.

I did everything with VB and Max used C#.

Lesson learned: more than half of audience are using 2008 and less then 20% use VB :-(

1) Sample: Web page with Listview, LINQ2XML, AJAX AlwaysvisibleControlextender

Lesson learned: audience love it, nearly everbody is thinking about web development

2) Sample by Max: WCF with REST which shows developers depending URI

Lesson learned: only few people are using WCF right now. Even less knows about REST or JSON.

3) Sample by Max: codeless list with WPF, Pictures, Border, Text

Lesson learned: only 1 % have used WPF, Audience miss better UI support ( eg Databinding) in Visual Studio. Max did it pure XAML and audience don't like it.

4) Sample dropped: Windows Mobile: plan was to shoot pictures live and upload it to WCF service. Not enough time, cool sample

Lesson learned: there is so much to tell about Visual Studio 2008.

5) Sample VSTO: Use Smart Tags to display picture of developers in Word document.

Lesson learned: not enough time to code. Only drag an drop of code snippet from toolbar was possible. After running the sample I could feel the "aha" in the room. Was something complete new which I believe have nobody seen before.

So back to my question

Where we are?

Visual Studio 2008 is a quite useful tool for the job. You can do more with it than even before. This would the chance to make upselling to our customers to offer eg alternative UI like mobile, web or WPF. The problem is we have not enough Microsoft minded developers.

Wed, 30 Jan 2008 19:56:37 GMT - AJAX drag& drop challenge: science fiction with web.preview


Drag and drop is one of the missing features from the final ASP.NET 2.0 AJAX Extensions 1.0 (what a name). On my research work I figured out several ways to implement drag and drop and add profile support.

My next sample uses the ASP.NET 3.5 Extensions Preview. Earlier builds were named ASP.NET AJAX Futures. Both includes a microsoft.web.preview.dll (version in this sample