Thursday, 6 June 2013

Call C Function On Vb.net

Call C Dll File Using Vb.net 

Here I have some steps for calling a functions of C language in vb.net:
1.Write a program and create a dll  file for it.
2.Open the VS2010 create a project and add a module in module write the program
    as shown  in figure:
3.You can  able to access the required function in this program the Dll name is "ishan.dll" and
    function name which we want to access, is 'add'.

Note:-
   After creating the dll file we can keep it in three place
    a.Past here "C:\Windows\System32".
    b.Keep in 'bin\Debug' folder of project directory Like:
       "C:\Users\Computer_name\Documents\Visual Studio 2010\
          Projects\WindowsAppForDll\WindowsAppForDll\bin\Debug".
   c.The third way is set the environment path ,give the path value where you store the file.
      path is separated by ';'.

Friday, 10 May 2013

Download Attachments From Email In Outlook To Local System.


                                          Download Attachments From Email
You can download the  attached item of emails in outlook and save it  some where. Just try this
code in your local system.
     
        Dim objOutlook As New Outlook.Application
        Dim objNS As Outlook.NameSpace = objOutlook.GetNamespace("MAPI")
        Dim objInboxFolder As Outlook.MAPIFolder = Nothing
        Dim objXYZFolder As Outlook.MAPIFolder = Nothing
        Dim objFailedFolder As Outlook.MAPIFolder = Nothing
        Dim emails As Items
        Dim email As MailItem
        Dim Num_mails As Integer = 0
        Dim email_attachment As Attachment
        Dim extension As String

        objInboxFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        objXYZFolder = objInboxFolder.Folders("Valuehire")
        objFailedFolder = objXYZFolder.Folders("Failed")

        emails = objXYZFolder.Items
        Num_mails = emails.Count

        Dim MyDocumentsDir As String = vbNull
        Dim DownloadDirName As String = vbNull
       
        MyDocumentsDir = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        DownloadDirName = MyDocumentsDir + "\Outlook Files\Valuehire\Downloads"

        If Num_mails > 0 Then
            For Each email In emails
                If email.Class = OlObjectClass.olMail Then
                    For Each email_attachment In email.Attachments
                        Dim filename As String = DownloadDirName + "\" + email_attachment.FileName
                        extension = Path.GetExtension(email_attachment.FileName)

                        If (extension = ".doc" Or extension = ".docx" Or extension = ".pdf" Or extension = ".rtf") Then
                            Try
                                email_attachment.SaveAsFile(filename)                               
                                MsgBox("File is downloaded")
                                Catch ex As System.Exception
                                If ex.Message.Contains("530") Then
                                    MsgBox("Your account is invalid. Please try again or contact your Administrator.")                                   
                                Else
                                     MsgBox("File is not downloaded")                                   
                                End If
                                Return
                            End Try
                        End If
                    Next email_attachment
                End If
            Next email
        End If

Notes- You can see above, in the first underline is pointed  to destination place where the file
 is store and second one for save the file in destination folder.

Friday, 3 May 2013

Connecting And Testing To A FTP Server


                            Connection To FTP Server  From Vs2010              

In this  blog i discuss on connection for ftp server, here is a small code ,i tried this in outlook
add_ins with successful result.But before  try this code you need server ftp address and  path
where file is located.

Dim ftpRequest As System.Net.FtpWebRequest
Dim clsStream As System.IO.Stream
Dim bFile() As Byte
Dim AccountName_var As String
Dim Password_var As String
Dim email_attachment As Attachments
Dim filename As String = DownloadDirName + "\" + email_attachment.FileName                       
  Try
                                email_attachment.SaveAsFile(filename)
                                ftpRequest = DirectCast(System.Net.WebRequest.Create("ftp://" + "xxx.xxx.xxx.xx" + "/" +
                                                        EmailID_var + "/" + email_attachment.FileName), System.Net.FtpWebRequest)
                                ftpRequest.Credentials = New System.Net.NetworkCredential(AccountName_var, Password_var)
                                ftpRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile
                                bFile = System.IO.File.ReadAllBytes(filename)
                                clsStream = ftpRequest.GetRequestStream()
                                clsStream.Write(bFile, 0, bFile.Length)
                                clsStream.Close()
                                clsStream.Dispose()
 Catch ex As System.Exception
                                If ex.Message.Contains("530") Then
                                    MsgBox("Your account is invalid. Please try again or contact your Administrator.")
                                Else
                                    MsgBox(ex.Message)
 End Try
               
Here the  'filename' is name of file with the file's path and 'xxx.xxx.xxx.xx' is replace by the ip address.

                                      Testing The Connection To FTP Server
After the connection we just test the connection,is it working or not. you see the highlighted 
yellow line ,this is the simple way for check the ftp connection.

Dim ValuehireRegKey As RegistryKey
        Dim AccountName_var As String
        Dim Password_var As String
        Dim EmailID_var As String
        ValuehireRegKey = Registry.CurrentUser.OpenSubKey("Software\Microsoft\Office\
                                                                                                         Outlook\Addins\Valuehire", True)
        AccountName_var = ValuehireRegKey.GetValue("Account")
        EmailID_var = ValuehireRegKey.GetValue("Email")
        Password_var = ValuehireRegKey.GetValue("Password")
        ValuehireRegKey.Close()
        Dim ftpRequest As System.Net.FtpWebRequest
        ftpRequest = DirectCast(System.Net.WebRequest.Create("ftp://118.139.182.77/" + 
                                                   EmailID_var + "/"), System.Net.FtpWebRequest)
        ftpRequest.Credentials = New System.Net.NetworkCredential(AccountName_var, Password_var)
        ftpRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectory
        Try
            ftpRequest.GetResponse()
            Return True
        Catch ex As System.Exception
            If ex.Message.Contains("530") Then
                MsgBox("Your account is invalid. Please try again or contact your Administrator.")
                Dim sf As New SettingsForm
                sf.ShowDialog()
            Else
                If ex.Message.Contains("Unable to connect to the remote server") Then
                    MsgBox("Could not connect to the server. Please try again or contact your Administrator.")
                Else
                    MsgBox(ex.Message)
                End If
            End If
            Return False
        End Try
    End Functionb




Tuesday, 23 April 2013

Setting Intervals Using Timer

                                                Setting Interval Through The Timer

Mostly timer is use for set the time for appropriate action in our application.I am make a 
small application that set the interval for to do something.
1)Open the VS any version, create a new project,or and new form in existing project in
    your computer.
2) Add new window form -
     Right click on project--> Click Add-->New Item-->Open new dialog box-->
     select Window form
3)After add the form  in project 
4)Design the form like that,see only red in circle-
5)Put the code inside the Check Box and Timer.
6)Here I call the function in timer,which is execute within the interval.
      Public Sub ShivFunction()
          MsgBox("file is downloaded")
      End Sub 



Office Ribbon Design Elements

Office Ribbon Design Element With VS 2010-

Here I describe about some feature and properties of ribbon design in office,in project it
can hold project on excel,word,power point,outlook,choose any one of the as you want.
Ribbon is use for add new tab in office,contain different type tools. In this blog i explore
feature with the outlook.So when we open the VS 2010 ,just follow the instruction -

   1)If you don't know how to open the outlook project then follow this  link.
   2)Here i give the  project name as 'SampleOutlookAddIn' .

   3)Right click on the project-->select Add-->New Item-->Open new dialog box.
   4)You have two type ribbon,Ribbon(visual designer) and Ribbon(XML),you can choose
      any one, just like i choose Ribbon(visual designer) here,give the name and click Add.

   5)Go to ribbon property--> ribbon type--> select 'Microsoft.Outlook.Explorer'.

   6)Drag-drop the tools in ribbon as shown in image.
      In image i show the ribbon contain Group,and group contain Box, box hold button and
      checkbox.You can change the name of 'AddIn' from property.
7)If You want to add custom type tab then go to property of tab and change it to 'custom'.


Now,here introduce some tools,used in ribbon
    a)Ribbon- Ribbon is hold the all tools like buttons,groups,checkbox,textbox etc.Used
       for built simple tab and custom tab.
    b)Tab-In ribbon we can add one or more  tab(simple tab and custom tab).
    c)Group- After the ribbon 'group' is an important element for collection of tools,and group is 
       contained by ribbon.
    d)Button-Button is like a simple button as in other application.
    e)Separator-This is use for separate and provide a some space ,give a line between two or
       more tools.
    f)Toggle Button-This is use for one time click,like a work as on/off, active/inactive
      able/enable act.
   g)Split Button- Button is Spite in two part one is for selection/clicking and other is see the list 
      own feature it may be collect a  buttons,checkbox etc.
   h)Button Group- This contain the buttons or it maintain the group of button/checkbox,but here 
      only one button/checkbox work at a time.
   j)Combo/Dropdown/Textbox, Checkbox/Level-Works same as visual basic tools. 

8)After run this project open outlook,  it look like-


Monday, 22 April 2013

Creating Directories Inside Outlook

Create A Directories And Sub Directories In Outlook-

Here I create the directories in outlook through the Outlook Addins in VS 2010, follow this steps-
1.Open the VS2010  choose the selected option show in the image.
2.After the open a new window double click on 'ThisAddIn.vb',open code space.
3.In code space put the code-
   a) Let us create  function CreateOutlookDirectories().
    b)Here i create a 'flag' variable for check existing of folder ,if require folder name is already exist
      then it is not create same name folder.
   c)We create 'Valuehire' name folder in outlook inbox and sub_folder named 'Failed'.
   d))Just follow the code-

 Public Sub CreateOutlookDirectories()
        Dim objOutlook As New Outlook.Application
        Dim objNS As Outlook.NameSpace = objOutlook.GetNamespace("MAPI")
        Dim objInboxFolder As Outlook.MAPIFolder = Nothing
        Dim objXYZFolder As Outlook.MAPIFolder = Nothing
        Dim objTransferredFolder As Outlook.MAPIFolder = Nothing
        Dim objFailedFolder As Outlook.MAPIFolder = Nothing
        Dim xyzExistsFlag As Boolean = False
        Dim FailedExistsFlag As Boolean = False

        objInboxFolder = objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)

        If objInboxFolder.Folders.Count > 0 Then

            For i = 1 To objInboxFolder.Folders.Count
                If objInboxFolder.Folders.Item(i).Name = "Valuehire" Then
                    xyzExistsFlag = True
                    objXYZFolder = objInboxFolder.Folders("Valuehire")
                End If
            Next
            If xyzExistsFlag = True Then
                If objXYZFolder.Folders.Count > 0 Then

                    For j = 1 To objXYZFolder.Folders.Count
                        If objXYZFolder.Folders.Item(j).Name = "Failed" Then
                            FailedExistsFlag = True
                        End If
                    Next
                    If FailedExistsFlag = False Then
                        objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
                    End If

                Else
                    objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
                End If

            Else
                objXYZFolder = objInboxFolder.Folders.Add("Valuehire", Outlook.OlDefaultFolders.olFolderInbox)
                objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
            End If
        Else
            objXYZFolder = objInboxFolder.Folders.Add("Valuehire", Outlook.OlDefaultFolders.olFolderInbox)
            objFailedFolder = objXYZFolder.Folders.Add("Failed", Outlook.OlDefaultFolders.olFolderInbox)
        End If

    End Sub 

4.Call the function in 'ThisAddIn_Startup()' 
     
   Private Sub ThisAddIn_Startup() Handles Me.Startup
          CreateOutlookDirectories()
   End Sub

and run the program and see the result-


Create And Delete A Direcotry From Local System

Programmatically  Create And Delete A Directory From Local System -

Here i describe about how to create and delete a folder/directory to your computer, there is
many way to do this,but i share only one way-

I take a wpf programming for this,you can make this also in different window form -
1.we take two buttons for one is create and second is for delete.
2.write the code in respected buttons ,shown as in image.

3.After run the  program ,you see the massage box ans also check the directory  which you give in program as path for verification of  the code,run or not!!!!