Monday, May 14, 2012

Stop Auto Update for Windows server

For successful  and cleaner SharePoint environment ,  stopping auto updates will be a nicer option as it will prevent any environment changes . To do this please make this registry change.


HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU
NoAutoUpdate   1

Thursday, April 26, 2012

Get a file via ftp using VBA





' Edit these variables to match your specifications
ftp_address          = "hosted.datascope.reuters.com"
ftp_username         = "6666666"
ftp_password         = "xxxxxxxxx"
ftp_remote_directory = "reports" ' Leave blank if uploading to root directory
ftp_files_to_put     = "abcdefg.xml"     ' You can use wildcards here (e.g. *.txt)

'On Error Resume Next
Set oScript = CreateObject("WSCRIPT.SHELL")
Set oFileSys = CreateObject("Scripting.FileSystemObject")
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Build our ftp-commands file
Set objTextFile = objFSO.CreateTextFile("test.ftp")
objTextFile.WriteLine "lcd ."
objTextFile.WriteLine "open " & ftp_address
objTextFile.WriteLine ftp_username
objTextFile.WriteLine ftp_password

' Check to see if we need to issue a 'cd' command
If ftp_remote_directory <> "" Then
   objTextFile.WriteLine "cd " & ftp_remote_directory
End If

objTextFile.WriteLine "prompt"

' If the file(s) is/are binary (i.e. .jpg, .mdb, etc..), uncomment the following line' objTextFile.WriteLine "binary"
' If there are multiple files to put, we need to use the command 'mput', instead of 'put'
If Instr(1, ftp_files_to_put, "*",1) Then
   objTextFile.WriteLine "mput " & ftp_files_to_put
Else
   objTextFile.WriteLine "get " & ftp_files_to_put
End If
objTextFile.WriteLine "bye"
objTextFile.Close
Set objTextFile = Nothing
' Use cmd.exe to run ftp.exe, parsing our newly created command file
strCMD = "ftp.exe -s:test.ftp"

'strTempFile = "C:\" & oFileSys.GetTempName( )
strTempFile = oFileSys.GetTempName( )

' Pipe output from cmd.exe to a temporary file (Not :| Steve)
Call oScript.Run ("cmd.exe /c " & strCMD & " > " & strTempFile, 0, True)

Set oFile = oFileSys.OpenTextFile (strTempFile, 1, False, 0)

On Error Resume Next
' Grab output from temporary file
strCommandResult = oFile.ReadAll
oFile.Close
' Delete the temporary & ftp-command files
Call oFileSys.DeleteFile( strTempFile, True )
Call objFSO.DeleteFile("test.ftp", True )
Set oFileSys = Nothing
Set objFSO = Nothing
' Print result of FTP session to screen

C# Sort dictionary containing objects

Hi After searching a lot over internet how to sort dictionary containing objects e.g Dictionary<string,myclass> I end up writing this simple but effective method please have a look .



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Dictionary<string, delta> mydict = new Dictionary<string, delta>();
            mydict.Add("a", new delta(true, 3,"ash1"));
            mydict.Add("d", new delta(false, 1,"bsh2"));
            mydict.Add("e", new delta(false, 1 , "ash3"));
            mydict.Add("b", new delta(true, 2 , "ash4"));
            IComparer<delta> myComparerorder = new compareorder() as IComparer<delta>;
            IComparer<delta> myComparerbool = new comparebool() as IComparer<delta>;
            IComparer<delta> myComparerstring = new comparestring() as IComparer<delta>;
            var sortedDict = mydict.OrderByDescending(x => (delta)x.Value, myComparerbool).ThenBy(x => (delta)x.Value, myComparerorder).ThenBy(x=>(delta)x.Value , myComparerstring);


            foreach (var key in sortedDict)
            {
                var _key = key.Key;
                var _delta = mydict[_key];
                Console.WriteLine(_delta.order + "---" + _delta.global + "----" + _delta.name);
            }
        }
    }
    public class delta
    {
        public bool global;
        public int order;
        public string name;
        public delta(bool _global,int _order,string _name)
        {


            global = _global;
            order = _order;
            name = _name;
        }
    }


    public class compareorder : IComparer<delta>
    {
        public int Compare(delta x, delta y)
        {
            if (x.order > y.order)
                return 1;
            if (x.order < y.order)
                return -1;
            else
                return 0;
        }
    }


    public class comparebool : IComparer<delta>
    {


        public int Compare(delta x, delta y)
        {
            return x.global.CompareTo(y.global);
        }
    }


    public class comparestring : IComparer<delta>
    {


        public int Compare(delta x, delta y)
        {
            return x.name.CompareTo(y.name);
        }
    }




}




The output of the above code will be:---


2---True----ash4
3---True----ash1
1---False----ash3
1---False----bsh2