Welcome to WindowsClient.net | Sign in | Join
in

WindowsClient.net

Learnings..

  • C# Casini/VS Web Server/WebDev.WebServer through code.-Self Learning Post

    If you've followed the post on running a cmd prompt from code this should be very simple.

    Firing the WebDevServer has the following format.

    WebDev.WebServer /port:XXXX/path:"YYYY".

    So the  XXXX represents the port number you want to start at and the YYYY represents the path of your web service.

    The "quotation" marks in the path are pretty important

    The following code will suffice

    string d = "/c WebDev.WebServer.exe /port:XXXX/path:\"YYYY"";

    System.Diagnostics.ProcessStartInfo procStartInfo =

    new System.Diagnostics.ProcessStartInfo("cmd", d);

    procStartInfo.WorkingDirectory = "C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\9.0";

    // The following commands are needed to redirect the standard output.

    // This means that it will be redirected to the Process.StandardOutput StreamReader.

    procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false;

    // Do not create the black window.

    procStartInfo.CreateNoWindow = true;

    // Now we create a process, assign its ProcessStartInfo and start it

    System.Diagnostics.Process proc = new System.Diagnostics.Process();

    proc.StartInfo = procStartInfo;

    proc.Start();

    Basically you need to bring the cmd prompt to the right working directory .Incase you are using VS2005 your working directory will be different so you should check to see which directory has the WebDev.WebServer.exe

    Until next time!

     Anshulee

    Posted Dec 03 2008, 05:51 PM by Anshulee with no comments
    Filed under:
  • C# Running Cmd prompt from code-- a Self learning post

    I haven't been blogging for a long time, basically because i don't get the time to create "well explained" blogs. So, since i am no "most popular blogger" anyway i am gonna start blogging for keeping a personal tab on things i am learning.

    So the upcoming blogs are not going to be too explanatory(just about enough for me to understand what i wrote when i want to refer it 2 yrs down the line). But if you are interested in any topic i write about specifically, do ask i will be happy to explain:-)

    This first one goes to explain how to run cmd from code to do an XCopy to copy a file(WebDev.WebServer.exe in this case) from one location to another

    //basically format of string is "/c XCopy.exe "source folder path" "destination folder path" /option"

    //the extra \ before a " allows a quotation mark within a string.

    //the /Y means overwrite without prompting if already present

    string d =
    "/c XCopy.exe \"C:\\Program Files\\Microsoft\\XXX\\WebDev.WebServer.exe.manifest\" \"C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\9.0\" /Y";

    System.Diagnostics.ProcessStartInfo procStartInfo =

    new System.Diagnostics.ProcessStartInfo("cmd", d);

    // procStartInfo.WorkingDirectory = "C:\\Program Files\\Microsoft SQL Server\\90\\Tools\\Binn";

    // The following commands are needed to redirect the standard output.

    // This means that it will be redirected to the Process.StandardOutput StreamReader.

    procStartInfo.RedirectStandardOutput = true; procStartInfo.UseShellExecute = false;

    // Do not create the black window.

    procStartInfo.CreateNoWindow = false;

    // Now we create a process, assign its ProcessStartInfo and start it

    proc = new System.Diagnostics.Process();

    proc.StartInfo = procStartInfo;

    proc.Start();

    // Get the output into a string

    result = proc.StandardOutput.ReadToEnd();

    // Display the command output.

    Console.WriteLine(result);

    The following should be in next

    1. Running WebDev server from code

    2.configuring webservice in IIS dynamically

    3.Custom actions in Setup project

    4.Few dos and donts for set up projects

    5.Checking and realizing n/w connectivity in code

    6. Running an sql script file from code

    Let me stop here before i increase the list so much that i don't reach point 1 also:-)

     

     

  • (WPF ListView/ TreeView)Get rid of that default (blue) selection colour!!

    As promised this next blog covers a very trivial but important problem. important because i think almost everyone would want to override this default behaviour of WPF and trivial because the solution is actually pretty simple.Atleast its simple now that i know it. it wasn't so simple for me earlier though;-)

    For this blog i feel pictorial rep is gonna be the easiest to follow .OK so the problem is this.

    I have a List View with ListView Items and everytime i select an item it turns Blue with a white foreground. Customer says i want Gray background and Blue font (weird choice i know..but then Customer is the King!). So how do we do this??

    We basically need to tweak the control template of a ListViewItem. Yeah..ListViewItem.. believe me the ListView is not at fault so changing the background, foreground , selection colour etc of the ListView doesn't help (you can try it if you have the time :-)).

    I think Expression Blend is the easiest way to tweak the control template and though as a developer i swear by VS but Blend does get an extra brownie point for this one.. so the following steps help us here. Open Expression Blend, create a new WPF application and put a ListView control on it. Then go on to add a few ListViewItems as follows.

    Do this 2-3 times to add 2-3 List view Items.

    Next get the control template of the ListViewItem.

    This will create a new style for the ListViewItem. It will ask you where you want to create the style. Since this really isn't your project the heirarchy doesn't matter, so keep it in the Window itself

    OK. Now Open the Window.xaml. You will find a new style under the Resources section.

    The Lines i have highlighted are our culprit. You can see a trigger defined for Selection which sets the background and foreground based on dynamic resources picked up depending on the theme of the OS the app is running on.

    So change the trigger values to what YOU want

     <Trigger Property="IsSelected" Value="true">
            <Setter Property="Background" TargetName="Bd" Value="Gray"/>
            <Setter Property="Foreground" Value="Blue"/>
      </Trigger>

    But this is not enough. You have created a style and given it a key. Which means that this style is applicable only to those ListViewItems to specifically subscribe to it saying Style={StaticResource ListViewItemStyle1}. This is not what we want. We want all the Items to follow this style. So remove the "x:key= ListViewItemStyle1" from the style definition.

    This will make the style applicable to all the UI elements of Target Type= "ListViewItem"(lower in the heirarchy ofcourse)

     Now run the app (f5) and select any ListView Item

    Now pick up this style definition and paste it in your app.xaml/ window.xaml depending on the heirarchy you want!

    This works for ListView/ TreeView atleast. I thinkt he same must be true for dropdowns etc also..so hope it helps you somehow!

    Till next time!

    Anshulee

     

  • Removing the Dotted border around selected WPF UI element

    The WPF app i have been working on looks great but there was a small visual irritant which i wasn't being able to get rid of. Everytime i clicked on a UI element..especially a ListViewItem, treeViewitem it would have this default selected look i.e a Blue background with a dotted boundary.Also the default selected look varies depending on the Theme of the OS.

    This Blue Background when selected is defined in the Control Template of the element under the Triggers section and can be commented out/ modified to change the default look.You can even force WPF to use a specific theme irrespective of the OS its working on .Hopefully i will be putting in another entry on how to overwrite the default theme of the OS if you want your app to look consisten across say Vista and Server 2003.

     My problem was the dotted line around the selected item. This would appear in buttons, treeview items, list view items..almost everywhere.

    It took me very long and a lot of trial and error to figure out the property responsible for this dotted line.The property is "FocusVisualStyle". You need to set it to {x:Null} to get rid of that evil dotted line.

     <ListViewItem Content="ListViewItem" FocusVisualStyle= "{x:Null}" />

    So if you are trying to get a smooth look which selecting your items in a Server 2003 environment

    FocusVisualStyle="{x:Null}" is the key!!

    Next in queue:-Getting rid of the default blue selected look and forcing WPF app to use a specific theme!!

    Until next time..

    anshulee

  • Exploring the OBA Composition Reference Toolkit (OCRT) !!

    Microsoft Recently announced version 2 of the OBA Composition Reference Toolkit. Microsoft has released a pretty intensive framework.Looks like the beginning of something big!!

     

    Version 1 had been announced at the Office Developers Conference in San Hose in February 2008. I had the opportunity to be a part of the conference and was pretty impressed with the potential this framework provides.

     The OBA Composition Reference Toolkit or OCRT as its called seems to be targetted at Information Workers who want to explore and experiment with the potential of componentized OBAs to make a composite Business Solution by combining the potential of the component OBAs. The best part is that now these Information workers can create these solutions and even deploy them in sharepoint  at the click of a few buttons..they don't need to run to their IT departments for support.

    The Set up guides and the hands on lab do a good job in explaining all the steps.Since i installed the whole system on  my box let me list down the main points of this app.I went through the source code available in the V2 to figure out some of these things..

    The Installation deploys the following on your system

    1. The OBA Composer:- A smart WPF application which provides an intuitive user interface to interact with the toolkit. View the sample Components installed by the system, mix and match the components to make your own OBA. Save it, deploy it in Sharepoint..view it in IE...use your OBA ..Open it..change it and deploy it again. The Composer does a good job of guiding the user as he composes the OBA. The "provisioning" as its called or deployment of the OBA is shown in a real-time updating window which shows all the components being provisioned etc

    2. Provisioning Service:- This is not very evident but the its the brain of the system.Though it does look like its all "Magic" and the Composer pretty much manages to abstract the complications behind deploying Lists ,VSTOs, invoking workflows, creating databases etc just at the click of a button, the secret lies in the Provisioning Service.The Provisioning Service is a Windows service deployed on your system which does the all the magic behind the scenes and actaully deploys all the components and connects them..

    3. OBA Administration:- Pages added to Application Management of your Sharepoint Central Admin to enable you to upload your own Components, set the security etc. The Components need to be created as per the Component Design and Packaging Guide listed in the documentation. As long as your components adhere to the standards mentioned there..all should be good. So you can upload the components from the Admin Pages and then use the OBA composer to mix and match with the other components to explore further possibilities

    4. Source Code:- This is the best part...The  Code seems to be well written, the OBA Composer is a WPF app and seems to be making use of a lot of WPF concepts like property/data triggers, templates,control templates, run time assignment of icons to tree views, multithreading etc. Should be interesting to explore for someone who wants to see the practical use of these concepts

    The data layer seems to be written in pure LINQ. Extensive use of C# 3.0 and LINQ features all through the application.

    I am glad the source code is exposed. I look forward to exploring it further!!

    Another useful feature was that all this information loaded into the OBA Admin pages and used in the Composer can be "Tagged" .This would help group OBAs based on the industry/domain they cater for.

    If you have ever worked with OBAs(Office Business Applications) or aspire to do so, then installing this OCRT is a must for you to understand the potential of combining the potency of the different independent solutions to create a new business solution.

    If you do install the OCRT, drop me a line .It would be interesting to discuss the potential and possibilities!!

    Meanwhile i intend to explore the source code..esp of the Composer and see if it can help me illustrate a few nice concepts!!

    Till Then!!

    Anshulee

  • (WPF)Figure out dynamically if the ListView ScrollViewer is showing!!

    I recently faced a situation where i had a databound ListView with a ItemTemplate consisting of a text block.The ListView is of a predefined height and width and the TextBlock is textwrapped and set to the same width as the ListView..

    Everything worked fine till the number of items in the ListView increased resulting in the Default ScrollViewer of the ListView showing up showing Vertical as well as horizontal scroll bars.The annoying aspect is that the scrollviewer uses the real estate of the ListView...

    So now the TextBlock can no longer be seen completely as it is hidden behind the vertical scrollbar and i need to use the horizontal scroll bar to view the complete text...I am sure many have faced this particular issue...

    So one way around is to check if the ScrollBar can be seen and if so then adjust the width of the text block.This is all fine except that there is no direct way to extract the scrollviewer of the ListView....

    The following steps can help you

    1. Hook on to the ListView.LayoutUpdated event
    2. The following lines of code in the LayoutUpdated event handler help extract the ScrollViewer(consider the Listview is called listView)
    Decorator border = VisualTreeHelper.GetChild(listView, 0) as Decorator;//Border is the first child of a Listview

    ScrollViewer scroll = border.Child as ScrollViewer;

         3.  Now we need to figure out of the ScrollBar is visible or not. ScrollViewer.VerticalScrollBarVisibility or ScrollViewer.IsVisible etc all proved useless in this case.

    ScrollViewer.VerticalScrollBarVisibility is Auto in this case and will show the value of Auto whether its seen or not. ScrollViewer.IsVisible will return true as we have not set it to false coz we want it to show up as and when required.

    The only property i could make use of here to figure out if the scrollViewer is showing a vertical scrollbar is

    ScrollViewer.ScrollableHeight. If the value is set to 0 then the scrollbar is not visible and if it is greater than 0 then it is visible.

    So using these steps i could figure out when i need to resize my textblock to prevent it from hiding behind the vertical scroll bar.

    Somehow i am not  very happy  about the use of ScrollViewer.ScrollableHeight but thats all i could find to help me...if you do figure out a better way...do drop me a line:-)

     Till then..

    Anshulee

     

  • Multiple Level Master Detail Binding in WPF(XAML)

    I’ve seen a couple of developers fumble with a LOT of Code when asked to implement a 2-3 level Master –detail form.

    So I put together a bit of code to showcase how easily it can be done with virtually no code (alteast no code behind!!) in WPF

    Consider the following problem statement:

    Create a form which lists a set of families in a dropdown.(Level 1)

    Depending on the family selected list the members of the family. List the sons and daughters in a dropdown(Level 2)

     

    Depending on the son or daughter selected, list their friends in a dropdown(Level 3)

    So your form should look like

    To make things more interesting, all this information about the families comes from this XML Document. Family.xml

    So how do we do this in WPF?.

    The following 4 Step process should suffice!!

    1.       Create an XML Data provider for the XML  Document and set the XPath to the Family Node

    <XmlDataProvider x:Key="dataSource" Source="Family.xml" XPath="/Families/Family"></XmlDataProvider> 

    2.       Create the UI in 2 layers  i.e there should be 3 grids let’s call them the  FamilyGrid, Son Grid and Daughter Grid

    So the structure is

    <Grid x:Name=”FamilyGrid”>

    <..Place the Level 1 controls here…i.e Family combobox, Father and Mother text blocks-->

                    <Grid  x:Name=”SonGrid”>

    <.. Place the Level 2 and Level 3 controls here..i.e the “Son” Combo box followed by the Son’s friends..>

                    </Grid>

    <Grid  x:Name=”DaughterGrid”>

    <.. Place the Level 2 and Level 3 controls here..i.e the “Daughter” Combo box followed by the Daughter’s friends..>

    </Grid>

                    </Grid>

    3.       Set the DataContexts of the Grids

    a.       Family Grid: Set the DataContext to the Family Node

    <Grid x: Name=”FamilyGrid” DataContext="{Binding Source={StaticResource  dataSource}}">

    b.      Son Grid: Set the DataContext to the “Son” Node within the current Binding

    <Grid x:Name="SonGrid" DataContext="{Binding XPath=Children/Sons/Son}">

    c.       Daughter’s Grid: Set the DataContext to the “Daughter” Node within the current Binding

    <Grid x:Name="DaughterGrid" DataContext="{Binding XPath=Children/Daughters/Daughter}">

    4.       Bind the Comboboxes to the required fields and set the IsSynchronizedWithCurrentItem= true

     As Highlighted above the key points here are

    ·         The DataContexts of the Grids which are set to the level of information which we want to show. Whenever a control does an “ItemSource= {Binding…}, the compiler will travel up the UI Heirarchy to find the first not- null data context.So it helps to set the datacontext at the “container” level if mutiple controls need to refer to a common data source.

     

     Since we have a hierarchy of grids and the family grid refers to the /Families/Family Node, we just need to keep setting the DataContext={Binding , XPath= <the XPath to the Node following the family node>}. DataContext={ Binding…} will take you to the /Families/Family node and the XPath will take you to your desired node

     

    ·         The Property IsSynchronizedWithCurrentItem which is being set to true in the comboboxes is the key here.When you bind a set of data to a value select control and set IsSynchronizedWithCurrentItem = true, what you are saying is “From this point onwards consider this data item as the selected item and refer to it for data for the ensuing controls”

     

    So when you select a family in the family combobox, and make it the “Current Selected” data item, the other comboboxes will refer to the data present in the selected family at the specified path , so Family/Son will search for the Son node within the selected Family

     So using a combination of DataContexts to refer to different levels of data and IsSynchronizedWithCurrentItem to set the currently selected data you can go upto n levels of master details binding,and you wudn’t have written a single line of code in you .cs fileJ

     

     You can find the solution for the above example hereMasterDetailBinding.zip.

     

    Happy Detailing!

    Anshulee

     

  • The One Stop Shop for Mix 08 related downloads

    I was going berserk trying to keep a tab of WHAT ALL has been advertised on Mix, before i hit this site

    Thanks to Sarah Perez for collating everything and sharing with us!!

    So Sarah's blog along with http://sessions.visitmix.com/ should keep you busy over the weekend!!

     

    Posted Mar 07 2008, 12:54 PM by Anshulee with no comments
    Filed under:
  • Mix 2008 Sessions- Already available

    There is still hope for us "unfortunate" ones who cannot attend the Mix 08 sessions live!!

    Get updated with the latest presentations uploaded at

    http://sessions.visitmix.com/

    I love the presentation of this site! 

    Happy Viewing!!

    Anshulee

    Posted Mar 07 2008, 12:38 PM by Anshulee with no comments
    Filed under:
  • Structured Navigation Using Page Functions!

    One of the new features WPF has given us windows programmers is the "Page" as the supposed equivalent of the html web page..information can now flow from one page to another as in a website by linking one page to another via a hyperlink .This gives users the  familiar web experience(and looks much better than windows popping up with every click!!)..

    Along with pages, WPF also introduces a concept known as Page Functions..but before i go there, lets examine WHY we need them!

    Hyperlink driven navigation in pages has the following drawbacks

    a) It is difficult to pass information between the host page and the calling page

    b) In case the host page called a task page to do some work , its difficult for the host page to know if the work was actually completed or not

    c) In some cases it is desired that the user should NOT be able to navigate back to the task page. For example once he has submitted the information he shouldn’t be allowed to go back using the Navigation service and change it. This is very difficult to achieve

    The first 2 points above i.e. a and b can be achieved in the traditional page + hyperlink combination using Application scope properties to pass information between them, though not in a very structured manner. However it is very difficult to remove the task page reference from the history.

     

    WPF has solved these issues by creating Page Functions.

    Essentially, page functions enable a style of navigation that is analogous to functions in procedural languages, which typically involves the following:

      • Calling a function.
      • Passing parameters to the function.
      • Performing processing from the function.
      • Calling other functions from the function.
      • Return results from the function to the calling code.
      • Cleaning up.

    Given below is the definition of a Page Function. To create a Page function you simple do a AddNewItemàPage Function into your solution.

     

    PageFunction.xaml

    <PageFunction

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        xmlns:sys="clr-namespace:System;assembly=mscorlib"

        x:Class="CSharp.TaskPageFunction"

        x:TypeArguments="sys:String"

        Title="Task Page Function" WindowWidth="250" WindowHeight="150">

      <Grid Margin="10"></Grid>

    </PageFunction>

     

    PageFunction.xaml.cs

    public partial class TaskPageFunction : PageFunction<String>

    {

        public TaskPageFunction()

        {

            InitializeComponent();

        }

    }

    The declaration is pretty much similar to a page. However Page Function is a generic class and needs a declaration of the Type of the value it will return.This is set in the  x:TypeArguments="sys:String" in the xaml configuration and correspondingly as <String> in the Page.xaml.cs file

    You can create your own custom types and use your page function to return custom information (If you are interested leave me a comment and i can upload an example!).

     

    Now that we know the concept of Page Function and how to define it. We’ll see how to create, call, pass values and get the results from a page function

     

    Creation and calling and passing value: It is same as creating an instance of a Page and navigation to it

    Say

    TaskPageFunction taskPageFunction = new TaskPageFunction()//Call an overloaded constructor if you want to pass information to it,

     this.NavigationService.Navigate(taskPageFunction); Getting return value from the task page

    In order to pass values back to the Calling page, Task page calls a method called OnReturn(). OnReturn is a protected virtual method which will be called with an instance of Generic ReturnEventArgs of the type same as the Type arguments you had specified for the page function.

     

    So whatever data you want to return will be sent to the OnReturn() function.

    For example in the Page function definition we created above, on clicking a submit button you want to pass the text entered by the user into a textbox called “NameTextBox” the code will be as under

     Public void SubmitClicked(sender object, RoutedEventAgrs args){OnReturn(new ReturnEventArgs<string>(this. NameTextBox.Text));} 

    The OnReturn() method in turn fires the Return event of the task page which the calling class has to hook onto.

     

    To summarize the following 3 parts of the code are needed to complete the navigation

     

    //create the page function, hook onto its Return event and navigate to it

    TaskPageFunction taskPageFunction = new TaskPageFunction()taskPageFunction.Return += taskPageFunction_Return; this.NavigationService.Navigate(taskPageFunction); 

    // the Page function will call ONReturn on completing its task

    OnReturn(new ReturnEventArgs<string>(this. NameTextBox.Text));

    The Calling page method delegated to receive the event will get called and will extract the information from the event args passed to it

     void taskPageFunction_Return(object sender, ReturnEventArgs<string> e) {  MessageBox.Show(“Name  Is “+ e.Result}      Removal of Page function ref from the Navigation history

    Every PageFunction /Page has a property called as RemoveFromJournal .Setting it to true removes it from the navigation history after the page has been navigated away from.

          By default a Page function has RemoveFromJournal set to true. So it will be removed  from history once its OnReturn has been called.

     

    Oh btw...this form of Navigation is called Structured Navigation in WPF Terminology!!

     

    Enjoy!

    Anshulee

  • Know me!!

    Oops..i didn't really introduce myself did i?? Well..here

    Name:- Anshulee Asthana

    Experience:- 4.5 years

    Hobbies:- Playing!!..may be no good at all..but i still enjoying playing...anything ...but it better be outdoors!!

    Tech Interests:- Anything to do with Windows Programming!!

    What am i doing here??:- Well i am here to show off a little and to learn a lot from you!!

  • Silverlight blueprint for Sharepoint!!

    Looks like Microsoft really does believe in creating an integration between all of its technologies and frameworks.

    The latest announcement at the Sharepoint conference at Seattle speaks of a Silverlight Blueprint for SharePoint .. This will allow SharePoint Developers building web parts to take advantage of Silverlight user interface components.

    Check it out!

    http://msdn2.microsoft.com/en-us/sharepoint/cc303301.aspx

    --Anshulee 

     

Page view counter