Search This Blog

Tuesday, March 4, 2014

ASP.NET System.Web

ASP.NET > System.Web

System.Web contains classes and interfaces that enable browser-server communication.





Rss Feed Reader Vb.net Example

VB.NET > XML > Rss Feed Reader






Example


 Dim url As String = "http://rss.cnn.com/rss/cnn_latest.rss"
        Dim rssFeed As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)
        Dim response = rssFeed.GetResponse()
        Dim rssStream = response.GetResponseStream()

        Dim rssDoc As New XmlDocument()
        rssDoc.Load(rssStream)
        Dim rssItems As XmlNodeList = rssDoc.SelectNodes("rss/channel/item")
        Dim i As Integer = 0
        Dim dt As DataTable = New DataTable("table")
        dt.Columns.Add("title", Type.GetType("System.String"))
        dt.Columns.Add("link", Type.GetType("System.String"))

        While i < rssItems.Count
            Dim node As XmlNode = rssItems.Item(i).SelectSingleNode("title")
            Dim title As String
            Dim link As String
            If node IsNot Nothing Then
                title = node.InnerText
            Else
                title = ""
            End If

            node = rssItems.Item(i).SelectSingleNode("link")
            If node IsNot Nothing Then
                link = node.InnerText
            Else
                link = ""
            End If
            Dim dr As DataRow = dt.NewRow()
            dr("title") = title
            dr("link") = link

            dt.Rows.Add(dr)

            i += 1
        End While

        DataGridView1.DataSource = dt


#Region Directive Visual Basic Example

Visual Basic > Directives > #Region

Collapses and hides sections of code.

Example:

Public Class Form1
#Region "Person"
    Public Class Person

    End Class
#End Region
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

End Class








Wednesday, February 26, 2014

Read XMLTYPE Oracle C#

C# > Oracle.DataAccess > Read XMLTYPE 

An OracleXmlType object represents an Oracle XMLType instance.

Example:


OracleConnection con = new OracleConnection() ;
con.ConnectionString = "Data Source=sid; User ID=xx; Password=xx; enlist=false; ";
con.Open();
OracleCommand xmlCmd = new OracleCommand();
xmlCmd.CommandText = "select xml from table ";
xmlCmd.Connection = con;
OracleDataReader poReader = xmlCmd.ExecuteReader();
OracleXmlType poXml;
while (poReader.Read())
{
     poXml = poReader.GetOracleXmlType(0);    
}

con.Close();




Tuesday, February 25, 2014

c# GuidAttribute Example

C# > InteropServices >  GuidAttribute 

Supplies an explicit Guid when an automatic GUID is undesirable.

When you write an application to be used as COM you have 
to give a unique name. In this case you need to apply GUID attribute.

Example

Class that is exported to COM with a fixed GUID


[GuidAttribute("bd2d60fa-8e40-4d06-ad6f-8760983efe33")]
public class ExposedToComClass
{
          
}






Friday, February 21, 2014

Get all services C#

C# > ServiceProcess > Service Controller

It is a Windows service that allows you to connect to a service.
You can manipulate it or get information about it.

Example:
Get list of all services

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class clsService
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public string Status { get; set; }
    }
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            ServiceController[] scServices;
            scServices = ServiceController.GetServices();
            List<clsService> lcs = new List<clsService>();
            foreach (ServiceController sc in scServices)
            {
                clsService cs = new clsService();
                cs.Name = sc.ServiceName;
                cs.Type = sc.ServiceType.ToString();
                cs.Status = sc.Status.ToString();
               
                lcs.Add(cs);
            }
            dgv.DataSource =lcs ;
        }
    }
}





Linq to SQL equivalent to TOP

C# > LINQ > Take

Take returns the first specified number of elements.

Example
Linq to SQL equivalent to TOP

var query = from q in dc.Queries.OrderBy(f => f.name).Take(10)