This is code when i create my sample web application i want to create html ui in back end code so i created using string builder.
if (dt.Rows.Count > 0)
            {
                StringBuilder strb = new StringBuilder();
                strb.Append("<br/><br/>");
                strb.Append("<table border='1' cellpadding='3'>");
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strb.Append("<tr><td>");
                    strb.Append(dt.Rows[i]["Subject"].ToString());
                    strb.Append("</td>");
                    strb.Append("<td>");
                    strb.Append("<input type=\"text\" name=\"subject\" id=\"txtSubject" + i.ToString() + "\" runat=\"server\" />");
                    strb.Append("<input type=\"hidden\" name=\"hidsubject\" id=\"hidSubject" + i.ToString() + "\" runat=\"server+\" value=" + dt.Rows[i]["Subject_ID"].ToString() + "/>");
                    strb.Append("</td></tr>");
                }
                //subject = subject + "," + dt.Rows[i]["Subject_ID"].ToString();
                //hidSubject.Value = subject;
                strb.Append("</table>");
                divMark.InnerHtml = strb.ToString();
            }
Read more ...

This solution i experienced. when i develop wpf application there i used combobox. when i try to add new student that time combobox items not reloaded. because of application loading time i loaded dynamically. so i don't no how to refresh the combobox list. After that i got this solution. when u add new item while after "objwindow.ShowDialog()" refresh the combobox.
 <ComboBox Name="Student" ItemsSource="{Binding Source={StaticResource Students}, XPath=Student/@StudentName}"
SelectionChanged="{pti:DelegateCreator student_Changed}" MinWidth="150"
Style="{StaticResource RequiredComboBox}" />
if you want to refresh from the controller your combobox name declare commonly like
ComboBox _studentList = FindLogicalNode(window, STUDENT_LIST) as ComboBox;
other wise your refresh from the xaml.cs file there your can declare like "this.FindResource"
private static void studentConfig_Click(object source, RoutedEventArgs args)
        {
            StudentConfiguration objwindow = new StudentConfiguration();
            objwindow.ShowDialog();
            (_studentList.FindResource("Students") as XmlDataProvider).Refresh();            
        }
Read more ...

This code when i want to get all my system printer list and set the default printer in my application while i used this code its working good. because of i want to do bar code printer so i have used more then one printer. Its very easy to get the system printer name using this method.
using System.Text;
using System.Windows.Forms;
using System.Management;
using System.Drawing.Printing;

namespace GetPrintersName
{
    public partial class Form1 : Form
    {
        public Form1()
        {           
            InitializeComponent();
        }
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        printer();
    }

    public static void printer() 
    {
        foreach (string printer in PrinterSettings.InstalledPrinters)
                 Console.WriteLine(printer);
 
            var printerSettings = new PrinterSettings();
            Console.WriteLine(string.Format("The default printer is: {0}",                         printerSettings.PrinterName));                 
     }
}
Read more ...

How to Add config file xml node using C#

Posted by senthil | 11:26:00 AM | | 0 comments »

This is code Add xml node in configuration file using C# method. Step:1 this is sample.config file
<TABLE>
<ROW>
    <COLUMN SOURCE="1" NAME="age" />
    <COLUMN SOURCE="3" NAME="firstname" />
    <COLUMN SOURCE="4" NAME="lastname" />
  </ROW>
</TABLE>
Step:2 I want to add xml node for my application configuration settings. so i want to add configuration setting using user interface Step:3 I created user interface one add page for add xml node. Step:4 I used this method and pass the xml value add the node.
public bool AddconfigFileXmlNode()
        {
            try
            {
                var doc = new XmlDocument();
                doc.Load("D:\\sample.config");
                 
                XmlNode profile;                
                profile = doc.SelectSingleNode("TABLE/ROW");

                XmlElement newChild = doc.CreateElement("COLUMN");

                newChild.SetAttribute("SOURCE", "4");
                newChild.SetAttribute("NAME", "lastname");  
            

                profile.AppendChild(newChild);
                doc.Save("D:\\sample.config");
            }
            catch { }
            return true;
        }
Read more ...

This is split the your string value using the special character
 private void SplitString()
        {
     string _BaseString="RIVE-SENT-KUMA-XXX"
            string[] seperate_filelds = _BaseString.Split('-');
            int counter = 0;
           // bool is_legit = false;

            foreach (string each_field in seperate_filelds)
            {
                counter++;
                // reading the first field which is prefix field
                if (counter == 1)
                {
     //fristValue = "RIVE";
                   string fristValue = each_field  ;

                }
                else if (counter == 2)
                {
                    //secondValue = "SENT";
                   string secondValue = each_field  ;
                }
  else if (counter == 3)
                {
                    //thirdValue = "SENT";
                   string secondValue = each_field  ;
                }
  else if (counter == 4)
                {
                    //furthValue = "XXXX";
                   string furthValue = each_field  ;
                }
               else
                { break; }
            }
                     
        }
Read more ...

Related Posts Plugin for WordPress, Blogger...