Wednesday, May 2, 2012

Compressing the ViewState of pages in ASP.net

Article Source : http://www.codeproject.com/Articles/14733/ViewState-Compression

the code
you just need to put this code in your page.


public byte[] Compress(byte[] data)
    {
        MemoryStream output = new MemoryStream();
        GZipStream gzip = new GZipStream(output,
                          CompressionMode.Compress, true);
        gzip.Write(data, 0, data.Length);
        gzip.Close();
        return output.ToArray();
    }

    public byte[] Decompress(byte[] data)
    {
        MemoryStream input = new MemoryStream();
        input.Write(data, 0, data.Length);
        input.Position = 0;
        GZipStream gzip = new GZipStream(input,
                          CompressionMode.Decompress, true);
        MemoryStream output = new MemoryStream();
        byte[] buff = new byte[64];
        int read = -1;
        read = gzip.Read(buff, 0, buff.Length);
        while (read > 0)
        {
            output.Write(buff, 0, read);
            read = gzip.Read(buff, 0, buff.Length);
        }
        gzip.Close();
        return output.ToArray();
    }

    protected override object LoadPageStateFromPersistenceMedium()
    {
        string viewState = Request.Form["__VSTATE"];
        byte[] bytes = Convert.FromBase64String(viewState);
        bytes = Decompress(bytes);
        LosFormatter formatter = new LosFormatter();
        return formatter.Deserialize(Convert.ToBase64String(bytes));
    }

    protected override void SavePageStateToPersistenceMedium(object viewState)
    {
        LosFormatter formatter = new LosFormatter();
        StringWriter writer = new StringWriter();
        formatter.Serialize(writer, viewState);
        string viewStateString = writer.ToString();
        byte[] bytes = Convert.FromBase64String(viewStateString);
        bytes = Compress(bytes);
        ClientScript.RegisterHiddenField("__VSTATE", Convert.ToBase64String(bytes));
    }


Tuesday, May 1, 2012

stsadm - upgrade solution script + deploy solution force


stsadm -o upgradesolution -name "Tatweer.Centers.Core.wsp" -filename "Tatweer.Centers.Core.wsp" -immediate -allowgacdeployment -allowcaspolicies
stsadm -o execadmsvcjobs

for deploying a solution with -force option

stsadm -o deploysolution -name "BackReport.wsp" -url "http:
//mdm-sp01:190" -immediate -allowgacdeployment -allowcaspolicies -force 



For updating the DLL File in sharepoint 2013 use the below script 

Set-location "C:\Users\ahindash\Desktop\Clearance\Finance"
[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")            
$publish = New-Object System.EnterpriseServices.Internal.Publish            

$publish.GacInstall("C:\Users\ahindash\Desktop\Clearance\Finance\ServiceRequestWFV3.dll")

Parameters: the first one for the path of the folder the second one is for the file path