Tuesday, 12 November 2013

How to fit Windows Form to any screen resolution?

" size = Screen.PrimaryScreen.WorkingArea.Size "
this line can only modify size of window-form
(it will not effect controls' locations & size). 
 
for fit your form in any window use 
"windowstate = FormWindowState.maximized"

Saturday, 6 July 2013

Open Excel workbooks in VB.NET Solutions








.NET WebBrowser Control

 

The following code is used to achieve the above:

 

Zip and Extract files in .NET

You must reference the assembly in your project-- System.IO.Compression.FileSystem

using System;
using System.IO;
using System.IO.Compression;

namespace ConsoleApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            string startPath = @"c:\example\start";
            string zipPath = @"c:\example\result.zip";
            string extractPath = @"c:\example\extract";

            ZipFile.CreateFromDirectory(startPath, zipPath);

            ZipFile.ExtractToDirectory(zipPath, extractPath);
        }
    }
}

Thursday, 7 March 2013

ProductVersion update for MSI Projects

The script is written in VBScript and is quite simple.

  • read the project file passed in the command line, e.g., Setup.vdproj
  • backup the original file, just in case something goes wrong ;-)
  • find the version number
  • increment the version number
  • replace the version number with the new value
  • replace the product code with a new GUID
  • replace the package code with a new GUID
  • write the updated project file back to disk

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''  Set version number of an MSI setup project from assembly
''  and update relevant GUIDs
''  Chirag Patel /03/03/2013

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

set args = wscript.arguments
if args.count < 2 then wscript.quit 1

set fso = CreateObject("Scripting.FileSystemObject")
set regex = new regexp
regex.global = true

'read current version from Version.txt file...
set versionFile = fso.OpenTextFile(args(1))
strVerTxtFile = versionFile.ReadAll
versionFile.Close

'find version text from file
regex.pattern = "(\d+(\.\d+)+)"
set Matches = regex.Execute(strVerTxtFile)

'split version info text using '.' and create new one with major.minor.svnrev
versionArray = Split(Matches(0).submatches(0), ".")
myNewVer = versionArray(0) & "." & versionArray(1) & "." & versionArray(3)

'Wscript.Echo myNewVer

'read all text from .vdproj of Setup Project
Set vdProjFile = fso.OpenTextFile(args(0))
textOfSetupProj = vdProjFile.ReadAll
vdProjFile.Close

'find and replace version number in .vdproj file
regex.pattern = "(""ProductVersion"" = ""8:)(\d+(\.\d+)+)"""
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & myNewVer & """")

'replace ProductCode
regex.pattern = "(""ProductCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & guid & """")

'replace PackageCode
regex.pattern = "(""PackageCode"" = ""8:)(\{.+\})"""
guid = CreateObject("Scriptlet.TypeLib").Guid
guid = left(guid, len(guid) - 2)
textOfSetupProj = regex.replace(textOfSetupProj, "$1" & guid & """")

'write back to .vbproj file with all the changes that we made above
set vdProjFileNew = fso.CreateTextfile(args(0), true)
vdProjFileNew.write(textOfSetupProj)
vdProjFileNew.close

Save IncrementSetupVersion.vbs 

For auto increment setup project version use scripts IncrementSetupVersion.vbs add them to pre-build events

first argument is setup project file, second is file with assembly version Example: "$(ProjectDir)..\SetupScript\IncrementSetupVersion.vbs" "$(ProjectDir)Setup.vdproj" "$(ProjectDir)..\version.txt"