Fetch twitter feed on your Form

Here’s a way to fetch twitter feed on form.

Twitter provides RSS feed of every account, provided account visibility is Public.

If you are using New twitter, you’ll have to find out your twitter feed link by

1] either leave new twitter preview and find RSS links on right sidebar, or
2] click on the RSS Feed icon in browser addressbar. It will probably show your favorites feed. Note the userid from URL.

Now, use that userid in this fashion :
http://twitter.com/statuses/user_timeline/userid.rss

Once you get your twitter feed rss url, its simple to fetch entries.

Sample code using my twitter feed :

You’ll need a RichTextBox and a Button on form. Keep default names.

	Dim items As Xml.XmlNodeList = FetchTwitterFeed("http://bit.ly/hbsM7i")
	'Iterate and print each title
	For Each item As System.Xml.XmlNode In items
		RichTextBox1.AppendText(item.ChildNodes(0).InnerText & vbCrLf)
		'childNodes(0) gives title
		'for rest node indices like link,time etc
		'check source string
	Next

Read more for FetchTwitterFeed() Function –

Continue reading

Advertisements

Copy folder using vb.net

Imports System.IO
Public Class Form1
	Private Sub CopyDirectory(ByVal SourcePath As String, ByVal DestPath As String, Optional ByVal Overwrite As Boolean = False)
		Dim SourceDir As DirectoryInfo = New DirectoryInfo(SourcePath)
		Dim DestDir As DirectoryInfo = New DirectoryInfo(DestPath)
		' the source directory must exist, otherwise throw an exception
		If SourceDir.Exists Then
			' if destination SubDir's parent SubDir does not exist throw an exception
			If Not DestDir.Parent.Exists Then
				Throw New DirectoryNotFoundException _
					("Destination directory does not exist: " + DestDir.Parent.FullName)
			End If
			If Not DestDir.Exists Then
				DestDir.Create()
			End If
			'copy all the files of the current directory
			Dim ChildFile As FileInfo
			For Each ChildFile In SourceDir.GetFiles()
				If Overwrite Then
					ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), True)
				Else
				' if Overwrite = false, copy the file only if it does not exist
				' this is done to avoid an IOException if a file already exists
				' this way the other files can be copied anyway...
					If Not File.Exists(Path.Combine(DestDir.FullName, ChildFile.Name)) Then
						ChildFile.CopyTo(Path.Combine(DestDir.FullName, ChildFile.Name), False)
					End If
				End If
			Next
			' copy all the sub-directories by recursively calling this same routine
			Dim SubDir As DirectoryInfo
			For Each SubDir In SourceDir.GetDirectories()
				CopyDirectory(SubDir.FullName, Path.Combine(DestDir.FullName, _
						SubDir.Name), Overwrite)
			Next
		Else
			Throw New DirectoryNotFoundException("Source directory does not exist: " + SourceDir.FullName)
	End If
End Sub
'Usage:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
	CopyDirectory("C:\zipMe", My.Computer.FileSystem.SpecialDirectories.MyDocuments & "\Folder1", False)
End Sub

Copy folder using Shell32 :-

Continue reading

Communicate between two Visual Basic Applications

How to communicate between 2 different visual basic applications.

Simple technique by using SendMessage()

	'Main app that tries to communicate with other
	Public Class Form1
		'Project App1

		Private Const APP2_MSG1 As Integer = 6541

		Declare Auto Function SendMessage Lib "user32.dll" _
		(ByVal hWnd As IntPtr, ByVal Msg As Integer, _
		 ByVal wParam As Integer, ByVal lParam As Integer) As Integer

		Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
		Handles Button1.Click
			Dim p() As Process = Process.GetProcessesByName("App2")
			If p.Count > 0 Then
				Dim hWnd As IntPtr = p(0).MainWindowHandle
				SendMessage(hWnd, APP2_MSG1, 0, 0)
				Debug.WriteLine("Msg sent")
			End If
		End Sub
	End Class

Read more to get code of Listening application

Continue reading

Get Screen information related to Form location

	If Screen.FromPoint(Me.Location).Primary Then
		'is primary
	Else
		'nope
	End If

Get device name on which form is currently on :

	Screen.FromPoint(Me.Location).DeviceName

Get Screen resolution of display, your form is currently on :

	Dim rect As Rectangle = Screen.FromPoint(Me.Location).Bounds

prevent opening popup in internet explorer

A common problem while using webBrowser control is open pop up windows in instance of Internet Explorer and not in your application.
There’s a simple way to prevent this.

Logic is to capture the event when New Window is opened | Grab Link | Open it programatically in our application | cancel opening IE.

and code would be :

Continue reading

Add BindingNavigator for DataGridView

To add a BindingNavigator for a DataGridView, even when there’s no DataSource like DataSet or DataTable in use, you can have DataGridView’s rows collection as DataSource for BindingSource.
And set that BindingSource to BindingSource property of BindingNavigator.

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load

        BindingSource2.DataSource = DataGridView1.Rows
        BindingNavigator1.BindingSource = BindingSource2

        'instead of adding event handler for MoveFirst,MoveLast,MoveNext,MovePrevious
        'chose this one. it will fire anyway
        AddHandler BindingNavigatorPositionItem.TextChanged, AddressOf bindingnavigator_PostionChanged

    End Sub

Continue reading