Sunday, July 31, 2011

How to create an Assembly in .Net

I will show here how to create a simple dll in .net using visual studio 2010, and to link it with other exe.
This may help a .net newbie like me.

Step 1: Create a class library



Step 2: Create a Console application





Step 3: Link the dynamic library

Use add() and sub() methods


Step 4:  Build and Run the project






read more 

Thursday, July 28, 2011

Learn Microsoft's PowerShell

Nice tutorial on Power shell: read

Why do we need PowerShell:

 Traditionally, an Administrator would launch the GUI, select the service, and then either stop or start it. Doesn't seem like a big deal until you are asked to stop a service on multiple computers. Through PowerShell Scripting you will be able to start, stop, and change status types of a service on multiple computers without much effort. Write a script, run-it, and then kick you feet up on the desk.



Sunday, July 3, 2011

Sharepoint 2010 using client object model to write into List

For accessing Sharepoint list we need two types of Classes:

1. Client Context Class
     Web property
     List property
          Get by title

2. ListItemCreationinformation Class


Step by Step procedure to access sharepoint list

Step 1 : Create a new WPF project


Step 2 :
  Create  a WPF application as show below:
 

Step 3 : Downlaod these sharepoint related dlls and place it in 14 hive folder of your machine  , in which sharepoint server is not installed.
  

 Step 4 : Embed this Code :

      

Friday, July 1, 2011

How to move your heavy attached files in a mail to your peronal website

Embed this VBA Macro in your Outlook :
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
 Dim totalSize As Double 'to store total size of the attachments
 Dim FileName As String  'path for the temp folder
 Dim strBody As String
 Dim strUname As String
 Dim i As Integer
 totalSize = 0
 strBody = "The attached files are placed in the below location" & vbCrLf
 i = 1
 strUname = Environ("USERNAME")
 If Item.Attachments.Count <> 0 Then 'Check if files are attached
   For Each At In Item.Attachments
       totalSize = totalSize + At.Size
   Next At
 'Check the total size of attached files are greater than 1MB
 If totalSize >= 10 Then
   For Each Atmt In Item.Attachments
      strBody = strBody & "http://mysite/personal/" & strUname & "/Personal%20Documents/" & Atmt & vbCrLf
      FileName = "C:\Users\" & strUname & "\AppData\Local\Temp\" & Trim(Atmt.FileName)
      Atmt.SaveAsFile FileName 'Save the attachments to Temp folder of your system
      UploadFile "C:\Users\" & strUname & "\AppData\Local\Temp\" & Atmt, "http://mysite/personal/" & strUname, "Personal Documents/" & Atmt.FileName, "Test title", "Test checkin comment"
   Next Atmt
 End If
  
   For i = 1 To Item.Attachments.Count 'Delete Attached files in mail
    Item.Attachments(1).Delete
   Next i
  
    Item.Body = Item.Body & strBody
    'MsgBox ("Total Size:" & totalSize & "KB")
    MsgBox "Done"
  
End If
 
 End Sub

Function StringToByteArray(str)
  Set stream = CreateObject("ADODB.Stream")
  stream.Open
  stream.Type = 2 ''adTypeText
  stream.Charset = "ascii"
  stream.WriteText str
  stream.Position = 0
  stream.Type = 1 ''adTypeBinary
  StringToByteArray = stream.Read()
  stream.Close
End Function

Sub UploadFile(sourcePath, siteUrl, docName, title, checkincomment)
strHeader = "method=put+document%3a12.0.4518.1016" + "&service_name=%2f" + "&document=[document_name=" + docName + ";meta_info=[vti_title%3bSW%7c" + title + "]]" + "&put_option=overwrite,createdir,migrationsemantics" + "&comment=" + "&keep%5fchecked%5fout=false" + vbLf
byteArray = StringToByteArray(strHeader)
Set stream = CreateObject("ADODB.Stream")
stream.Open
stream.Type = 1 ''adTypeBinary
stream.Write byteArray
Set stream2 = CreateObject("ADODB.Stream")
stream2.Open
stream2.Type = 1 ''adTypeBinary
stream2.LoadFromFile sourcePath
stream2.CopyTo stream, -1
stream.Position = 0
Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
xmlHttp.Open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", False
xmlHttp.setRequestHeader "Content-Type", "application/x-vermeer-urlencoded"
xmlHttp.setRequestHeader "X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"
xmlHttp.setRequestHeader "User-Agent", "FrontPage"
xmlHttp.Send stream
 If xmlHttp.Status = 200 Then
 If InStr(xmlHttp.responseText, "successfully") = 0 Then
  MsgBox "ERROR:" & vbCrLf & xmlHttp.responseText
  Else
  ''Checkin
  strHeader = "method=checkin+document%3a12.0.4518.1016" + "&service_name=%2f" + "&document_name=" & docName + "&comment=" + checkincomment + "&keep%5fchecked%5fout=false" + vbLf
  Set xmlHttp = CreateObject("MSXML2.XMLHTTP")
  xmlHttp.Open "POST", siteUrl + "/_vti_bin/_vti_aut/author.dll", False
  xmlHttp.setRequestHeader "Content-Type", "application/x-vermeer-urlencoded"
  xmlHttp.setRequestHeader "X-Vermeer-Content-Type", "application/x-vermeer-urlencoded"
  xmlHttp.setRequestHeader "User-Agent", "FrontPage"
  xmlHttp.Send strHeader
  End If
  End If
  If xmlHttp.Status / 100 <> 2 Then
   MsgBox "ERROR: status = " & xmlHttp.Status & vbCrLf & xmlHttp.responseText
   End If
End Sub
Function UserNameWindows() As String
Dim UserName As String
UserName = Environ("USERNAME")
'return UserName
End Function