Asp.net & Sql server fundas with Rajat Jaiswal

November 8, 2009

WPF Windows Persentaion Foundation with me PART- II

Filed under: Asp.net, Silverlight, WPF — indiandotnet @ 12:35 pm
Tags: , , ,

Hello friends,
In this session we are going to take a look how do we connect a silver light application with database.
So here I would like to say that there are basically 4 options by which you can handle database in silver light application.
1) WCF for Silver light
2) Ado.net Data Services
3) Web services
4) RIA Services (need to explore more)

Here I will explain how to connect your WPF Silver light application with database using well know Web service.
It’s easy and I think we all already work on some part of Web services.

So let’s start with it.
We have added a silver light navigation project. In navigation silver light project part we have added 2 new pages employee, register page.
Employee page is for show employee list,And register page is for register employee.


Just see project structure as below.

projectPhoto

And In web part we have added a new web service with name my services.
Whose functionality to save, updates, Delete, and read all employee record.
As shown in below fig.

MyWebService

Now our next step is how to integrate this web service with silver light.
For this we add a services reference in our navigation project with the help of Add services reference menu as shown below.

AddServices

Now you can rename name space according to your choice.

If you do not get any error in referencing then till now you are ok with your work.
Now our next step is calling web method in our pages.
Here I am taking first page which is employee list
We are calling web method which returns all employee lists so here we go.

Private Sub EmployeePage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
Try
Dim myBinding As New ServiceModel.BasicHttpBinding()
Dim myEndPoint As New ServiceModel.EndpointAddress(New Uri(“http://localhost/MyTest/MyWebService.asmx”, UriKind.Absolute))
Dim proxy As New MyWebServiceSoapClient(myBinding, myEndPoint)
proxy.pub_ReadAllDataAsync()
AddHandler proxy.pub_ReadAllDataCompleted, AddressOf proxy_ReadAllEmployeeCompleted

Catch ex As Exception

End Try
End Sub

Private Sub proxy_ReadAllEmployeeCompleted(ByVal sender As Object, ByVal e As myService.pub_ReadAllDataCompletedEventArgs)
Try
Me.myGrid.ItemsSource = e.Result
Catch ex As Exception
Me.HeaderText.Text = ex.InnerException.Message.ToString
End Try
End Sub

Now things to remember here
1) Dim myBinding As New ServiceModel.BasicHttpBinding()
Its shows the binding is http binding
2) Dim myEndPoint As New ServiceModel.EndpointAddress(New Uri(“http://localhost/MyTest/MyWebService.asmx”, UriKind.Absolute))
Here the path can be absolute or relative.

3) Next you have to call web method like we have call here proxy.pub_ReadAllDataAsync()
4) once we have call the method asyncronously then we have to make a event handler like we have create here

AddHandler proxy.pub_ReadAllDataCompleted, AddressOf proxy_ReadAllEmployeeCompleted

5) when the asyncronous method is complete we have to take result complete argument and covert according to our requirement.
I have just bind the result to datagrid and get below screen.
Just see below.

employeeList

So friends in this way we can call web service in a Silverlight application.

Still we can use DataServices, RIA services, and WCF services for data manipulation application.

Hope in next few chapter we will take this example and work on it.

That’s all friends, thanks for reading the article.

Happy programming!

Thanks
Rajat

November 1, 2009

WPF Windows Persentaion Foundation with me PART- I

Filed under: Asp.net, Silverlight, WPF — indiandotnet @ 9:43 am
Tags: , ,

Hello friends,

Today we will discuss one of the most popular technologies which are silver light.
Before going forward you have some query in your mind. As I have so we will first solve that. See following questions.
1. What is Silver light?
Answer: – Silver Light is programmable web browser plug in, that enable feature such like vector graphics, animation and audio, video play back. It provide cross browser compatibility.
Its main aim to provide RIA (Rich Internet Application).Its Consistency with WPF (Windows Presentation Foundation). XAML (extensible Application Markup Language) is base of Silver light.
Its main use to provide end user a rich web application experience
Silver light basically used for RIA (Rich Internet Application) and with help of it we can make user friendly and all browser supported web sites.

2. What is XAML?
Answer: – XAML is core of Windows Presentation foundation. Its full form is Extensible Application Markup Language it’s just like a xml language with certain fixed tags. Like canvas, rectangle, grid etc…

3) From where I can download toolkit?
Answer: – We can download silver light 3.0 toolkits from http://www.silverlight.net site which is official site.

Here I will explain basic example of silver light. We are going to make a simple add 2 integer programs. I know you all aware of this but I started this for step by step progress in silver light.
For this you have to first install 3.0.
Once you have installed silver light 3.0 you will get following projects in asp.net new project window. Just select silver light application in this.

NewProject

Once you have selected this then next screen comes up for the web site or web application selection. As shown below. I have selected web application.

SilverlightOption

After selecting web application project you will get 2 projects in your solution explorer one is for silver light in which there will be .XAML file. And another one is web application which is used to call XAML file in the compile format which is called XAP.

ProjectExplore
Now we start our actual work of making 2 digit sums in silver light application
For this we have to select mainPage.xaml.
In this XAML page we have to put all the control which is requiring like textbox, label or Text Block and button.
Suppose we have to add a TextBlock in page then see below lines

 Here x:Name is like id in our ASPX page it should be unique. Grid.Row = 0 and grid.column =0 shows position in grid.

Now similarly if you want to add a label and Textbox and button then
You have to follow below code.
<dataInput:Label x:Name=”lblResult” Grid.Row=”3″ Grid.ColumnSpan=”2″ HorizontalAlignment=”Center”></dataInput:Label>

<TextBox x:Name=”txtSecond” Width=”100″ HorizontalAlignment=”Left” Grid.Row=”1″ Grid.Column=”1″></TextBox >

< Button Name=”btnAdd” Content=”Add” Click=”btnAdd_Click” Width=”100″Grid.Row=”2″ Grid.ColumnSpan=”2″ HorizontalAlignment = “Center” >
</Button >
So the main this which you have to concentrate for alignment, colors.
In Next post we will come up with some solid project base & tool kit understanding.

till than  happy programming.

Thanks
Rajat

October 31, 2009

Nice utilities for Web Developer

Filed under: Asp.net, JQery — indiandotnet @ 12:18 pm
Tags: , , ,

Hello friends,

Today I come up with some useful list which help you in web development and good news is that its all free.
1) “FIREBUG” :-
Basically “FIREBUG” is add in for FireFox. It’s a great utility helps a lot to design web pages. As a developer I am mostly intrested in programming not designing.But this utility help me in solving designing issues. With the help of it you can manage designing ,CSS issues.
You can download this from https://addons.mozilla.org/en-US/firefox/addon/1843
2) Web Development Helper:-
This one is another useful utitly for web developer to improve performance. Its basically help you to determine which page taking how much time to response.It also help other area also like script finding. It has dom Inspector also. You can take help of this tool in various way.
You can download this from http://projects.nikhilk.net/WebDevHelper
3) Deep Zoom composer:- If you are working on Silverlight also then you can use Deep Zoom composer.it has very nice feature for images.
You can dowload this from http://www.microsoft.com/downloads/details.aspx?familyid=457b17b7-52bf-4bda-87a3-fa8a4673f8bf&displaylang=en

So just dowload & use this tools and improve your code.

Happy programming!

Thanks …
Your host
Rajat

October 25, 2009

How to change VS.NET 2008 IDE colorful and make it attractive in 5 minutes?

Filed under: Asp.net — indiandotnet @ 5:41 pm

Hello friends,
I know you are some time bored by same IDE. So here I am helping you out to make your IDE environment colorful as shown below fig.

IDE

Microsoft gives you full hands on IDE Environment to make your IDE attractive and enjoy dot net programming.
So for this you have to follow below steps.
1) Go to tool –> import and export Setting

1
2) Select the option as shown below.

2
3) In next step you can save your existing IDE Settings as shown below fig.

3
4)in next step just browse your require IDE settings (all the IDE settings has extension “VSSettings”) Like “rajat.vsSettings” just browse the file and click on finish button and what you will see is amazed cool coloful VS IDE.

4
I have attached some of the files just rename them with .vsSettings.

1) Colourful black

2) IndianTouch

3)RajatSpecial

Remember to rename this doc file to “.VsSettings”

Just use the wizard and you will get attractive IDE.
So enjoy colorful programming and IDE.
Make your coding colorful.

Thanks & regards
Rajat Jaiswal

October 4, 2009

Basic Threading with dotnet

Filed under: Asp.net — indiandotnet @ 1:04 pm
Tags: , ,

Hello friends,
Some time I really scared when I listen threading, but when I dive in threading pool its really fun and interesting also.
As per my knowledge what ever I got by learning from different books and web sites I will give you some basic knowledge which you will use and enjoy.
So first thing is what is threading? So here we go. When we talk about multi tasking, multi processing then threading word comes in action. Suppose you have a agile code which will run on a button click but the problem is when user click the button its hang up user screen for a while but you want user screen to be free and allow user to do some other task which he wants. Or similar thing in code also.
In this situation you require threading. It will improve user interaction and performance of your code also.

So start with basic the base class in dot net for threading is System.Threading

I will just write a code how to start a thread so it will much better to understand.

Suppose on button click we want to create a thread which will count number
Private Sub btnStartThread_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartThread.Click

Dim myThread As Threading.Thread = New System.Threading.Thread(New Threading.ThreadStart(AddressOf Me.pvt_NumberCounter))
myThread.Start()
MsgBox(“Next statement after thread!!!!”, MsgBoxStyle.Critical, “Rajat”)

End Sub

In the above lines what we are doing we are creating a delegate for a method which pvt_NumberCounter which count the number and assign it to mythread object.
Then to start thread or to activate thread we wrote mythread.start()
Which make thread active. Method pvt_NumberCounter() get in action.
While after mythread.start() statement message box also execute.
Means controls remain in start thread button.

In this way the thread can start.
There are some states of thread which will call thread state by which we can know what is the current position or state of a thread. For understanding thread you must understand thread state. Go through below fig and table.

ThreadStates

Action

ThreadState

A thread is created within the common language runtime.

Unstarted

A thread calls Start

Running

The thread starts running.

Running

The thread calls Sleep

WaitSleepJoin

The thread calls Wait on another object.

WaitSleepJoin

The thread calls Join on another thread.

WaitSleepJoin

Another thread calls Interrupt

Running

Another thread calls Suspend

SuspendRequested

The thread responds to a Suspend request.

Suspended

Another thread calls Resume

Running

Another thread calls Abort

AbortRequested

The thread responds to a Abort request.

Stopped

A thread is terminated.

Stopped

 

 

 

 

 

 

 

Now your mind has one question we started Thread, we have seen thread state but how to kill a thread explicitly I know you are very destructive mind : D but it was also in my mind so here is simple property which we have to use.
Which is Abort(). Sounds interesting.
You can kill a thread explicitly by thread.abort() statement.
So friends its over for me for this article i will bring some more stuff later on.
till then keep programming, keep visiting.
Thanks
Rajat

How to Start and kill a process (exe) From dot net

Filed under: Asp.net — indiandotnet @ 11:55 am
Tags: , ,

Hello friends,
First of all sorry for such a late post bit busy in some other stuff but come back with bang.
Today I will show you some simple but very interesting topic. So first topic is how to call a process from your code. And how to kill a particular process from your code.
Its code is very simple just needs to understand once then you are perfect in this.
The first thing you need to know there is base class for process which is System.Diagnostics
I am showing you code right here so please with me for few moments.
I am opening a Microsoft word application here.

Imports System
Imports System.Diagnostics
Imports System.Diagnostics.Process

Private Sub btnStartProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStartProcess.Click
Try
Dim oProcess As Process
Dim startInfo As New ProcessStartInfo
startInfo.FileName = “winword.exe”
oProcess = Process.Start(startInfo)
Catch ex As Exception
Throw ex
End Try
End Sub

In this way you can open a new Microsoft word application in similar manner you can open different other process. And also pass. Command line arguments to them.

Now if you want to close this application then its also easy. Just see below code and you will be master in that.

Private Sub btncloseProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncloseProcess.Click
Try
Dim oProcess As Process
Process.GetProcessesByName(“winword.exe”)
oProcess.Kill()
Catch ex As Exception
Throw ex
End Try
End Sub

If you know the id of process then it could be more specific. To kill particular instance.
In this way you can create and kill a process.
In next session I will come up with some more interesting topics till than do your best enjoy programming, enjoy dot net.
Thanks & regards
Rajat

August 22, 2009

Understand ftp with asp.net in 5 Minutes Part- IInd

Filed under: Asp.net — indiandotnet @ 6:50 pm
Tags: , ,

Hello Friends,

 In last article we have did how to upload a file I know you are very eager to know how to download a file.  I am not taking much time here and will introduce you below code by which you can download a file. It just likes our earlier upload ftp file.Its screen is just like below.

  DownloadFTP

On the button click we did following thing

  Protected Sub btnDownload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDownload.Click

        Try

            Dim ftpRes As FtpWebRequest = DirectCast(FtpWebRequest.Create(Me.txtFtp.Text & “/” & Me.txtRemoteFileName.Text), FtpWebRequest)

            ftpRes.Credentials = New NetworkCredential(Me.txtUserName.Text, Me.txtPassword.Text)

            ftpRes = DirectCast(WebRequest.Create(Me.txtFtp.Text & “/” & Me.txtRemoteFileName.Text), FtpWebRequest)

            ftpRes.Credentials = New NetworkCredential(Me.txtUserName.Text, Me.txtPassword.Text)

            ftpRes.Method = WebRequestMethods.Ftp.DownloadFile

            ftpRes.UseBinary = True

            Dim myFtpWebResponse As FtpWebResponse = ftpRes.GetResponse()

            Dim myStreamWriter As StreamWriter

            myStreamWriter = New StreamWriter(“c:\Downloads\” & Me.txtRemoteFileName.Text)

            myStreamWriter.Write(New StreamReader(myFtpWebResponse.GetResponseStream()).ReadToEnd)

            myStreamWriter.Close()

            myFtpWebResponse.Close()

        Catch eh As System.Net.WebException

            Response.Write(eh.Message)

        Catch ex As Exception

            Throw ex

        End Try

    End Sub

Here  The main important thing is method which is download file as you see in above code.

We just take response of ftp and read the stream of this with the help of GetResponseStream().ReadToEnd.

Rest all the thing is same like our old code for file upload.

I hope you got with the above code. 

Thanks & Enjoy coding

Your host

Rajat Jaiswal

August 16, 2009

Understand FTP with asp.net in 5 minutes part-Ist

Filed under: Asp.net — indiandotnet @ 6:57 pm
Tags: , , ,

Hello Friends,
Today I am going to share you new thing in asp.net 2.0 which is “FTP object”. Earlier in dot net 1.1 versions there is many problem to handle “FTP”, means if you want to upload or download a file then you have to do socket programming.
Which I don’t like really but after 2.0 this problem is resolved dot net provide great solution which allow us to connect with ftp and do operation.
I will explain you with my example. So today we took how to upload a file on ftp.
For this I have design following page.

FTPUpload
On this page there is 3 text box & file upload control basically which is
txtFtp – which keep ftp url like ftp://myftp.com
txtUserName – which keep ftp username for credential
txtPassword – which keep ftp password for credential
ctrlFlup – which keep path from where we have to upload file.

There is a button which is btnUpload on page. On click of this page we are going to upload the selected file.
So in code behind our first and most important statement is import J
Just see below code
Imports System.Net
Imports System
Imports System.Net
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
Try
Dim ftpRes As FtpWebRequest = DirectCast(FtpWebRequest.Create(Me.txtFtp.Text & “/” & Me.ctrlflUp.FileName), FtpWebRequest)
ftpRes.Credentials = New NetworkCredential(Me.txtUserName.Text, Me.txtPassword.Text)
ftpRes.Method = System.Net.WebRequestMethods.Ftp.UploadFile
Dim b As Byte() = Me.ctrlflUp.FileBytes
Dim fstream As System.IO.Stream = ftpRes.GetRequestStream()
fstream.Write(b, 0, b.Length)
fstream.Close()
fstream.Dispose()
Dim myresponse As FtpWebResponse = DirectCast(ftpRes.GetResponse, FtpWebResponse)
Response.Write(myresponse.StatusDescription)
Catch eh As System.Net.WebException
Response.Write(eh.Message)
Catch ex As Exception
Throw ex
End Try
End Sub
End Class

Here I will explain you the ftpwebrequest is the object which interact with FTP.
So when button upload is click we first create a object of ftp web request.
Once the object is created its credential is required for which we create a new network credential and just pass username & password.
After this you will find another important statement which is Web Request method.
Basically its notify that what user want to do import file, upload file, change directory etc.
In Next step what ever the file which we want to upload just convert that in byte array.
By file upload object as shown below
Dim b as byte() = me.ctrlflUp.fileBytes()
Once it done we just create a stream to write file on ftp.
So we just create a IO stream and write file on ftp.
To get response from Ftp as you know FTP has special command and status so we use ftp web response object.
If there is proper status then we can say our file is uploaded successfully.
In next Session we are going to download file from ftp with the help of this object.
Till then enjoy programming
Enjoy ftp.

Your friend
Rajat Jaiswal

August 10, 2009

How to read Resource files in our code by LINQ to XML ?

Filed under: Asp.net, LINQ, XML — indiandotnet @ 4:43 am
Tags: , , , ,

Hello friends,

Sorry for such a late post. Currently I am busy in too many works so not getting enough time to talk with you.

Today I am posting an interesting work which is how to read a resource file in our code with the help of LINQ TO SQL.

I can say only one thing which is its simple and easy to use. Just copy paste below code and you will get what to want.

Before code I will explain you that resource file is just like xml which has attributes and value and that particular attributes is your key.

 

Now we need to fetch value for particular key for a file for this you have to write below code. Where bv_strFileName is your resource file name and bv_strKey is key for which you need value.

Public Shared Function pub_LangaugeValue(ByVal bv_strFile As String, ByVal bv_strKey As String) As String

Try

Dim strValue As String = “”

Dim resxXML As New XDocument

resxXML = XDocument.Load(bv_strFile)

Dim a = From data In resxXML.Root.Descendants(“data”) _

Where data.Attribute(“name”).Value = bv_strKey _

Select New With {.resxA = data.Attribute(“name”).Value, .ResxValue = data.Element(“value”).Value}

If a.Count() > 0 Then

strValue = a.FirstOrDefault().ResxValue.ToString()

Else

strValue = bv_strKey

End If

Return strValue

Catch ex As Exception

Throw ex

End Try

End Function ‘pub_LangaugeValue

 

Where bv_strFileName is full path name of our resource file and bv_strkey is the key for which we need to find the value.

Below is example how to use it our aspx.

Suppose we want to read LabelResource1.text value in Spanish whose file name is home.aspx.es.resx.

 

Then we have to call the above function like below.

Response.write(pub_LanguageValue(server.mapPath(“/App_LocalResources/home.aspx.es.resx”),”LabelResource1.text”)

With the help of above code.

We can get key’s value from different resource file.

 

Thanks

Rajat Jaiswal

July 3, 2009

Finding Refrences of table ,function in Sql Server by simple query

Filed under: Sql server — indiandotnet @ 5:38 pm
Tags: , , ,

Hello Friends,
Most of the time you need how many refrences for particulare table, function or procedure.
In that case if you are not aware of command which I am showing below you will do lot of work.
But if you see below command
It helps you a lot in finding your refrences

SELECT *
FROM sys.procedures
WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE ‘%tblStudent%’

Here in like you can put tableName, function name or store procedure name what ever you want.
And you will got supprise when the result came. It will give you all the refrences related to that particular name.

So enjoy SQL SERVER.
Enjoy tricks.

Thanks 
Rajat Jaiswal

Next Page »

Blog at WordPress.com.