Get all the Machine name under the Network

Posted August 12, 2009 by idrisgani
Categories: C#

Goto -> Add refrence -> Add System.DirectoryServices

The following code will add the list of machine name under the network into the Combobox.

Use the following code in your .CS file

using System.DirectoryServices;

using System.Net;

DirectoryEntry parent = new DirectoryEntry(“WinNT:”);
foreach (DirectoryEntry dm in parent.Children)
{
if (dm.SchemaClassName == “Domain”)
Console.WriteLine(“Domain {0}”, dm.Name);
else
continue;

// Scan Computers on this domain
DirectoryEntry coParent = new DirectoryEntry(“WinNT://” + dm.Name);
foreach (DirectoryEntry client in coParent.Children)
{
if (client.SchemaClassName == “Computer”)
Console.WriteLine(“    Computer {0}”, client.Name);
else
continue;
// The computer may be in the directory, but not online
try
{
comboBox1.Items.Add(client.Name);
}
catch (Exception) { }
}
}

ReportService methods used in RSS File to deploy SQL reports

Posted June 4, 2009 by idrisgani
Categories: SQL Reports

CreateFolder(folder,parent,properties())
Parameters:
Folder as string
The name of the new folder.
Parent as string
The full path name of the parent folder to which to add the new folder.
Properties
An array of Property[] objects that defines the property names and values to set for the folder.
Eg:
Public Sub Main()
Dim name As String = “ReportFolder”
Dim parent As String = “/”
Dim fullpath As String = parent + name

‘Common CatalogItem properties
Dim descprop As New [Property]
descprop.Name = “Description”
descprop.Value = “”
Dim hiddenprop As New [Property]
hiddenprop.Name = “Hidden”
hiddenprop.Value = “False”

Dim props(1) As [Property]
props(0) = descprop
props(1) = hiddenprop

Try
RS.CreateFolder(name, parent, props)
Console.WriteLine(“Folder created: {0}”, name)
Catch e As SoapException
If e.Detail.Item(“ErrorCode”).InnerText = “rsItemAlreadyExists” Then
Console.WriteLine(“Folder / Reports already exists and cannot be overwritten”)
Else
Console.WriteLine(“Error : ” + e.Detail.Item(“ErrorCode”).InnerText + ” (” + e.Detail.Item(“Message”).InnerText + “)”)
End If
End Try
End Sub

CreateReport(Report,parent,overwrite,definition,properties())
Parameters:
Report as String
The name of the new report.
Parent as String
The full path name of the parent folder to which to add the report.
Overwrite
A Boolean expression that indicates whether an existing report with the same name in the location specified should be overwritten.
Definition
The report definition to publish to the report server.
Properties
An array of Property[] objects that contains the property names and values to set for the report.
Return Value:
An array of Warning[] objects that describes any warnings that occurred when the report definition was validated.
Eg:
The following example demonstrates how to take backup of report, create/publish a report and set a datasource to it.

Public Sub Main()
Dim Reportname as String = “SampleReport”
Dim parent As String = “/ParentFolder/Subfolder”
Dim location As String = parent + “\” + Reportname
Dim overwrite As Boolean = True
Dim reportContents As Byte() = Nothing
Dim warnings As Warning() = Nothing
Dim fullpath As String = parent + “/” + name

‘Common CatalogItem properties
Dim descprop As New [Property]
descprop.Name = “Description”
descprop.Value = “”
Dim hiddenprop As New [Property]
hiddenprop.Name = “Hidden”
hiddenprop.Value = “False”

Dim props(1) As [Property]
props(0) = descprop
props(1) = hiddenprop

‘Read RDL definition from disk
Try
Dim stream As FileStream = File.OpenRead(location)
reportContents = New [Byte](stream.Length-1) {}
stream.Read(reportContents, 0, CInt(stream.Length))
stream.Close()

warnings = RS.CreateReport(name, parent, overwrite, reportContents, props)

If Not (warnings Is Nothing) Then
Dim warning As Warning
For Each warning In warnings
Console.WriteLine(Warning.Message)
Next warning
Else
Console.WriteLine(“Report: {0} published successfully with no warnings”, name)
End If

‘Set report DataSource references
Dim dataSources(0) As DataSource

Dim dsr0 As New DataSourceReference
dsr0.Reference = “/Data Sources/DatasourceName”
Dim ds0 As New DataSource
ds0.Item = CType(dsr0, DataSourceDefinitionOrReference)
ds0.Name=”SMS”
dataSources(0) = ds0

RS.SetItemDataSources(fullpath, dataSources)

Console.Writeline(“Report DataSources set successfully”)

Catch e As IOException
Console.WriteLine(e.Message)
Catch e As SoapException
Console.WriteLine(“Error : ” + e.Detail.Item(“ErrorCode”).InnerText + ” (” + e.Detail.Item(“Message”).InnerText + “)”)
End Try
End Sub

CreateDatasource(datasource,parent,overwrite,definition,properties())
Parameters:
DataSource
The name of the data source.
Parent as String
The full path name of the parent folder that contains the data source.
Overwrite
A Boolean expression that indicates whether an existing data source with the same name in the location specified should be overwritten.
Definition
A DataSourceDefinition object that describes the connection properties for the data source.
Properties
An array of Property[] objects that defines the property names and values to set for the data source.
Eg:

Public Sub Main()
Dim name As String = “Datasourcename”
Dim parent As String = “/Data Sources”

‘Common CatalogItem properties
Dim descprop As New [Property]
descprop.Name = “Description”
descprop.Value = “”
Dim hiddenprop As New [Property]
hiddenprop.Name = “Hidden”
hiddenprop.Value = “False”

Dim props(1) As [Property]
props(0) = descprop
props(1) = hiddenprop

Dim definition As New DataSourceDefinition
definition.CredentialRetrieval = CredentialRetrievalEnum.Store
definition.ConnectString = “Data Source=; Initial Catalog= “
definition.Enabled = True
definition.EnabledSpecified = True
definition.Extension = “SQL”
definition.ImpersonateUser = False
definition.ImpersonateUserSpecified = True
definition.UserName = “”
definition.Password = “”
definition.WindowsCredentials = False
definition.OriginalConnectStringExpressionBased = False
definition.UseOriginalConnectString = False

Try
RS.CreateDataSource(name, parent,True, definition, props)
Console.WriteLine(“DataSource created successfully”)

Console.WriteLine(“You must supply the password using Report Manager to use this DataSource”)

Catch e As SoapException
Console.WriteLine(“Error : ” + e.Detail.Item(“ErrorCode”).InnerText + ” (” + e.Detail.Item(“Message”).InnerText + “)”)
End Try
End Sub

CreateLinkedReport(Report,parent,link,properties())
Parameters:
Report as String
The name of the new linked report.
Parent as String
The full path name of the parent folder to which to add the new report.
Link as String
The full path name of the report that will be used for the report definition.
Properties
An array of Property[] objects that defines the property names and values to set for the linked report.
Eg:

Public Sub Main()
Dim overwrite As Boolean = True
Dim name As String = “OriginalReportName”
Dim parent As String = “/path”
Dim fullpath As String = parent + “/” + name

‘Common CatalogItem properties
Dim descprop As New [Property]
descprop.Name = “Description”
descprop.Value = “”
Dim hiddenprop As New [Property]
hiddenprop.Name = “Hidden”
hiddenprop.Value = “False”

Dim props(1) As [Property]
props(0) = descprop
props(1) = hiddenprop

Try
RS.CreateLinkedReport(name,parent, “/OrignalPath/Reportname”, props)

Console.WriteLine(“Linked Report published successfully”)
Catch e As SoapException
If e.Detail.Item(“ErrorCode”).InnerText = “rsItemAlreadyExists” Then
If overwrite Then
RS.DeleteItem(fullpath)
RS.CreateLinkedReport(name,parent, “/GoldenGate/Ascend_Claims_Not_In_Golden_Gate”, props)

Console.WriteLine(“Linked Report: published successfully”)
Else
End If
Else
Console.WriteLine(“Error : ” + e.Detail.Item(“ErrorCode”).InnerText + ” (” + e.Detail.Item(“Message”).InnerText + “)”)
End If
End Try
End Sub

Get Object list from database

Posted April 22, 2009 by idrisgani
Categories: SQL

SELECT NAME,crdate FROM Sysobjects WHERE TYPE=‘U’ AND category=0 ORDER BY name – Get User tables

SELECT NAME,crdate FROM Sysobjects WHERE TYPE=‘FN’ AND category=0 ORDER BY NAME –Get User Defined Functions

Select NAME,crdate from sysobjects where type = ‘P’ and category = 0 ORDER BY NAME –Get Stored Procedures

SELECT NAME,crdate FROM Sysobjects WHERE TYPE=‘V’ AND category=0   ORDER BY NAME –Get Views

Focusing a Div Element using JavaScript

Posted April 22, 2009 by idrisgani
Categories: ASP.Net, Code Snippets, Tips and Tricks

The following code is used to focus a div element.It seems Focus is an inbuilt method which allows you to focus on the corresponding div element.

<div id=”map_canvas”  onmouseover=”focus(this)”/>

Find For A Particular Column In A Database using SqlServer

Posted December 26, 2008 by idrisgani
Categories: SQL

SELECT so.name as tablename, sc.name as columnname from sysobjects so

JOIN syscolumns sc

on sc.id = so.id and sc.name like ‘<<Column Name>>’

and so.xtype = ‘U’

Source : http://www.sqlservercentral.com/scripts/TSQL/64706/

Reading and Writing Text Files

Posted September 9, 2008 by idrisgani
Categories: C#

Writing Text Data to a File
using System;
using System.IO;

namespace SampleWrite1
{
class FileWriter
{
static void Main(string[] args)
{
// create a writer and open the file
TextWriter tw = new StreamWriter(“date.txt”);

// write a line of text to the file
tw.WriteLine(DateTime.Now);

// close the stream
tw.Close();
}
}
}

Reading Text Data from a File
using System;
using System.IO;

namespace SampleRead1
{
class FileReader
{
static void Main(string[] args)
{
// create reader & open file
Textreader tr = new StreamReader(“date.txt”);

// read a line of text
Console.WriteLine(tr.ReadLine());

// close the stream
tr.Close();
}
}
}

SQLXMLCOMMAND

Posted September 9, 2008 by idrisgani
Categories: C#

Fill Grid Using SQLXMLCOMMAND
string coString = “Provider=sqloledb;data source=”+
“diablo;userid=sa;password=mypassword;initial catalog=pubs”;
SqlXmlCommand co = new SqlXmlCommand(coString);
XmlReader xmlRead = new XmlReader();
DataSet ds = new DataSet();
co.CommandType = SqlXmlCommandType.Sql;
co.CommandText = “select * from Students for xml Auto”;
xmlRead = co.ExecuteXmlReader;
ds.ReadXml(xmlRead);
this.DataGrid1.DataSource = ds.Tables[0];

SQLXMLCOMMAND AND SQLXMLADAPTER
string coString = “Provider=sqloledb;data source=diablo;” +
“userid=sa;password=mypassword;initial catalog=pubs”
SqlXmlCommand cmd = new SqlXmlCommand(coString);
cmd.RootTag = “Root”;
cmd.CommandText = @” Students [@St_lname = "Stringer"]“;
cmd.CommandType = SqlXmlCommandType.XPath;
cmd.SchemaPath = “..\ Students.xsd”;
DataSet ds = new DataSet();
SqlXmlAdapter ad = new SqlXmlAdapter(cmd);
ad.Fill(ds);
this.DataGrid1.DataSource = ds;

SQLXMLCOMMAND TO SAVE XML FILE
string coString = “Provider=sqloledb;data source=”+
“diablo;userid=sa;password=mypassword;initial catalog=pubs”
SqlXmlCommand cmd = new SqlXmlCommand(coString);
XmlReader xr;
XmlDocument xDoc = new XmlDocument();
DataSet ds = new DataSet();
cmd.RootTag = “Authors” ;
cmd.ClientSideXml = True;
cmd.CommandText = “exec spAllStudents for XML nested”;
xr = cmd.ExecuteXmlReader();
xDoc.Load(xr);
xDoc.Save(“c:\testClientside.xml”); //save the output to a file
ds.ReadXml(“c:\testClientside.xml”); //read the file into a dataset
this.DataGrid1.DataSource = ds; //bind the datagrid to the dataset

Using Parameters with SqlXMLCommand
string coString = “Provider=sqloledb;;datasource=tpol;” +
“userid=sa;password=mypassword;initial catalog=pubs”
SqlXmlCommand cmd = new SqlXmlCommand(coString);
SqlXmlParameter param;
xAdp = New SqlXmlAdapter(cmd);
xDs = New DataSet();
cmd.RootTag = “Students”;
cmd.CommandType = SqlXmlCommandType.Sql;
cmd.CommandText = “select * from Students where st_lname = ? for xml auto”;
param = cmd.CreateParameter;
param.Value = this.ListBox1.SelectedItem;
xAdp.Fill(xDs);
this.DataGrid1.DataSource = xDs;

Split Multiline text using VB

Posted June 20, 2008 by idrisgani
Categories: VB.Net

Dim i As Integer
Dim line() As String
Dim j As Integer
Dim str As String
Dim str1 As String
line = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(line)
If Len(line(i)) > 10 Then
str = line(i)
While Not Len(str) = 0
str1 = Mid(str, 1, 10)
Label1.Caption = Label1.Caption & str1 & vbLf
str = Mid(str, Len(str1) + 1, Len(line(i)))
Wend
Else
Label1.Caption = Label1.Caption & line(i) & vbLf
End If
Next

Hide Frame using Same Button

Posted May 28, 2008 by idrisgani
Categories: Code Snippets

 <script type=”text/javascript”> 

var tabShow=0; 
function hideremote()  
 

 

{if (tabShow == 1)

 {if(document.all) {parent.document.body.cols=“25%,75%”;

tabShow = 0;

return;

}}

if(tabShow == 0) {

if (document.all)

{parent.document.body.cols=“0%,100%” ;

tabShow = 1;

}} </script>
 
”Call the script in HTML code, Add a Button in a Page
<input type=”button” value=”Show/Hide” onclick=”javascript:hideremote()”>

Pass Query String using Window.open Method

Posted May 10, 2008 by idrisgani
Categories: ASP.Net, Tips and Tricks

 

 

 

 

Dim 

popupScript As String = “window.open(‘ITES_vgrid.aspx?batchid=” & _ ddlbatchname.SelectedValue & “‘” & “, ‘CustomPopUp’, “

& _

 

 

 

“‘width=500, height=500, menubar=no, resizable=yes’);”

 

 

If (Not ClientScript.IsStartupScriptRegistered(“popup”)) Then

ClientScript.RegisterStartupScript(

Me.GetType(), “popup”, popupScript, True

)

 

 

 

End If