This is all the USB device read from your local machine using C#. I am working in wpf windows application. When i want to read my system USB Device i got this sample code. This code every easy to learn and implement as you want. just copy and past in your application.
public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

  static void Main()
        {
            var usbDevices = GetUSBDevices();

            foreach (var usbDevice in usbDevices)
            {
                Console.WriteLine("Device ID: {0}, PNP Device ID: {1}, Description: {2}",
                    usbDevice.DeviceID, usbDevice.PNPDevideID, usbDevice.Description);
            }

            Console.Read();
        }


        static List<USBDeviceInfo> GetUSBDevices()
        {
            List<USBDeviceInfo> devices = new List<USBDeviceInfo>();

            ManagementObjectCollection collection;
            using (var searcher = new ManagementObjectSearcher(@"Select * From Win32_USBHub"))
                collection = searcher.Get();

            foreach (var device in collection)
            {
                devices.Add(new USBDeviceInfo(
                (string)device.GetPropertyValue("DeviceID"),
                (string)device.GetPropertyValue("PNPDeviceID"),
                (string)device.GetPropertyValue("Description")
                ));
            }

            collection.Dispose();
            return devices;
        }
    }

    class USBDeviceInfo
    {
        public USBDeviceInfo(string deviceID, string pnpDeviceID, string description)
        {
            this.DeviceID = deviceID;
            this.PNPDeviceID = pnpDeviceID;
            this.Description = description;
        }
        public string DeviceID { get; private set; }
        public string PNPDeviceID { get; private set; }
        public string Description { get; private set; }
    } 
Read more ...

LINQ using XML data load to combobox.

Posted by senthil | 8:40:00 PM | , , | 0 comments »

To use LINQ to XML you will need to import a two of namespaces.
using System.Linq;
using System.Xml.Linq;


private void StudentsLoad()
{
  var xElem = XElement.Load(@"Student.xml");

  var students = from prod in xElem.Descendants("Student")
           orderby prod.Element("StudentName").Value
           select prod.Element("StudentName").Value;

  lstStudents.DataContext = students;
}
Read more ...

When i want to xml data load to the combobox . i got this solution. Its very simple to load the xml data. this the xml data.
<Items>
  <Item>
    <ItemId>1</ItemId>
    <ItemName>Architecting ASP.NET Applications
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
  <Item>
    <ItemId>2</ItemId>
    <ItemName>Fundamentals of N-Tier eBook</ItemName>
    <Price>19.95</Price>
  </Item>
     ...
     ...
  <Item>
    <ItemId>3</ItemId>
    <ItemName>Security for ASP.NET Developers
                 eBook</ItemName>
    <Price>19.95</Price>
  </Item>
</Items>
this is stackpanel resource load, it will load on window loaded
<StackPanel.Resources>
  <XmlDataProvider x:Key="ItemsData"
                   Source="/Items.xml"
                   XPath="Items/Item" />
</StackPanel.Resources>
Its a combobox wirte like this, i loaded in ItemName if you want price load to another one combobox just change the xPath and then automatically load the price data to the combobox.
<ComboBox Name="Items" MinWidth="200" Style="{StaticResource RequiredComboBox}" Foreground="Black" FontSize="30" IsSynchronizedWithCurrentItem="False" SelectedIndex="0">
                    <ComboBox.ItemContainerStyle>
                        <Style TargetType="ComboBoxItem">
                            <Setter Property="Padding" Value="5">
                            </Setter>
                        </Style>
                    </ComboBox.ItemContainerStyle>
                    <ComboBox.ItemsSource>
                        <Binding Source="{StaticResource ItemsData}" XPath="ItemName" />
                    </ComboBox.ItemsSource>
                </ComboBox>
Read more ...

This code XML data load to gridview in wpf application. when i want to xml data load to the gridview using back end csharp code. its very simple. 1. Create DataSet object and then 2. Load the xml file to dataset using readxml property. 3. dataset value pass to the gridview itemsource.
DataSet dataSet = new DataSet();

dataSet.ReadXml(@"C:\Students\Students.xml"); 

dataGrid1.ItemsSource = dataSet.Tables[0].DefaultView; 
Read more ...

I am working in wpf application when i want to open the child window from Parent window button click. that time i am getting this solution. Just write Parent window click event method like this.
private void Button_Click(object sender, RoutedEventArgs e)
        {            
            window2 win2= new window2();
            win2.Show();
            this.Close();
        }
Read more ...

This code create an round button in wpf application using ResourceDictionary. create an xaml file like this.
<ResourceDictionary 
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Style x:Key="RoundButtonTemplate" TargetType="Button">
        <Setter Property="Background" Value="Brown"/>
        <Setter Property="Foreground" Value="White" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Border CornerRadius="15" Background="{TemplateBinding Background}"
                                BorderThickness="1">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center">

                        </ContentPresenter>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>
after that create and main window xaml file and then just call this RoundButtonTemplate style using Window.Resources load the GlassButton.xaml file and then call the StaticResource in main window like this.
<Window x:Class="GlassButton.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Glass Buttons" Height="228" Width="272">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources\GlassButton.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>
<Grid>
 <StackPanel Orientation="Horizontal">
<Button Focusable="False"
        Style="{StaticResource RoundButtonTemplate}"
        Width="264"
       Height="90" 
       Grid.Row="0"
       Margin="0,0,0,0"
       HorizontalAlignment="Center"
       BorderBrush="#FFF"
       Name="PasswordButton"
       Click="PasswordButton_Click"> 
                                             
 </Button>
  </StackPanel>
</Grid>
</Window>
Read more ...

This is code i have an exprience when i want to create a round button in my application i have used this code. this is one way of the create round button in wpf application. if we want change the color and Radial Gradient color and also we can able to apply the Transform using opacity. its very useful i have past the following code.
<Button Width="100" Height="100">
                <Button.Template>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <Ellipse Stroke="#5ECF5E"
                         StrokeThickness="2">
                                <Ellipse.Fill>
                                    <RadialGradientBrush GradientOrigin="0.496,1.052">
                                        <RadialGradientBrush.RelativeTransform>
                                            <TransformGroup>
                                                <ScaleTransform CenterX="0.5" CenterY="0.5" ScaleX="1.5" ScaleY="1.5"/>
                                                <TranslateTransform X="0.02" Y="0.2"/>
                                            </TransformGroup>
                                        </RadialGradientBrush.RelativeTransform>
                                        <GradientStop Offset="1" Color="#5ECF5E"/>
                                        <GradientStop Offset="0.2" Color="#FFFFFFFF"/>
                                    </RadialGradientBrush>
                                </Ellipse.Fill>
                            </Ellipse>
                            <ContentPresenter HorizontalAlignment="Center"
                                  VerticalAlignment="Center"/>
                        </Grid>
                    </ControlTemplate>
                </Button.Template>
            </Button>
another one way to create the round button.
<Button  Width="100" Height="100" Content="Abcd">
        <Button.Template>
            <ControlTemplate TargetType="{x:Type Button}">
                <Grid>
                <Ellipse Fill="Red"/>
                    <ContentPresenter Content="{TemplateBinding Content}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                </Grid>
            </ControlTemplate>
        </Button.Template>
    </Button>
this code create an rectangle button with color and Radial Gradient color and also we can able to apply the Transform using opacity.
<UserControl x:Class="WindowsFormsApplication8.UserControl1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Height="154" Width="177">
    <Grid>
        
        <Rectangle Name="rectangle1" Stroke="Black" RadiusX="10" RadiusY="10" >
        </Rectangle>
 
        <Button Name="rectangle2" Foreground="Black" Margin="3,3,3,3" >
            <Button.Background >
                <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
                    <GradientStop Color="Green" Offset="0.0" />
                    <GradientStop Color="White" Offset="0.9" />
                </LinearGradientBrush>
            </Button.Background>
        </Button>
    </Grid>
</UserControl>
Read more ...

This Warning i have experienced. When i going to change the Windows .Net Framework installer i had changed .Net Framework version 3.5 to version 4.0 that time i'm getting this issue. Its a easy to fix in this issue. Just Right click the setup solution explorer file and click the "view" and then click "Launch Conditions" the Issue founded.


and then Right Click the Launch Conditions "Properties Windows"




after that select the correct .Net Framework version





after that Right click the setup solution explorer file and select the properties




there is select on "Prerequsities" selection correct .Net Framework version.


Read more ...

When i click the button i want to assign the textbox value from another class.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        Download myDownload = new Download();
        static string textBoxString;
        public Form1()
        {
            InitializeComponent();
        }

        public static string TextboxText
        {
            set { textBoxString = value; }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            myDownload.Do();
            textBox1.Text = textBoxString;
            textBox1.Invalidate();
        }
    }

    public class Download
    {
        public void Do()
        {
            Form1.TextboxText = "My text";
        }
    }
}

An even better solution would be to define the possible interactions in an interface, and let that interface be the contract between your form and the other class. That way the class is completely decoupled from the form, and can use anyting implementing the interface (which opens the door for far easier testing):

interface IYourForm
{
    string FirstName { get; set; }
}

In your form class:


class YourFormClass : Form, IYourForm
{
    // lots of other code here

    public string FirstName
    {
        get { return firstNameTextBox.Text; }
        set { firstNameTextBox.Text = value; }
    }
}
...and the class:


class SomeClass
{
    private readonly IYourForm form;
    public SomeClass(IYourForm form)
    {
        this.form = form;
    }

    // and so on

}
Read more ...

Windows installer error

Posted by senthil | 1:26:00 PM | , | 0 comments »

When i install my wpf installer while getting error like this. any body know about this issue.

Question :-

Error 1001. Unable to get installer types in the C:\\YM\ConfigUI\ConfigUI.exe assembly. --> Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

 The description for Event ID 11001 from source MsiInstaller cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.

 If the event originated on another computer, the display information had to be saved with the event.

 The following information was included with the event: Product: YottaMark Case Labeling Solution -- Error 1001. Error 1001. Unable to get installer types in the C:\YM\ConfigUI\ConfigUI.exe assembly. --> Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
(NULL)
(NULL)
 (NULL)
(NULL)
(NULL)
 the message resource is present but the message is not found in the string/message table

Answer : -

Based on the error message in your second comment, it appears that your ConfigUI.exe assembly has been added as a Custom Action with the InstallerClass property set to true, but either no installer classes could be found in the exe or the exe could not be loaded due to missing dependencies.

You can see the list of Custom Actions by right-clicking on the installer project, selecting View and then Custom Actions.

If your exe does not can an installer class, then you can remove it from the list of custom actions.

If it does contain an installer class, then the issue is going to be missing dependencies. If fuslogvw doesn't work for you (it has always helped resolve this kind of issue for us), you can carefully review the list of references in the exe's project and compare them to what is listed in the installer project.

The other trick that we use is to examine the install directory while the error message is displayed on the screen. We can often see that DLLs are missing by doing this, usually because the path was entered incorrectly in the DLL entry within the installer project or because a condition was set incorrectly.

Read more ...

Related Posts Plugin for WordPress, Blogger...