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 



Wednesday, April 18, 2012

FIX: Secure VPN Connection terminated locally by the Client Reason 442: Failed to enable Virtual Adapter


  1. Press Windows and R key to open Run window, type inservices.msc
  2. Stop the Cisco Systems … service
  3. Stop the Internet Connection Sharing (ICS) service
  4. Right click on ICS service and choose Properties. Then changeStartup type to Disabled or Manual
    I prefer to stop this service until you finish working on the VPN 
  5. Start Cisco Systems … service
  6. Done. Now create a VPN connection, error 442 no more !

Wednesday, April 11, 2012

Adding WSP Solution to SharePoint 2010 using Power Shell


1.    Open SharePoint 2010 Management Shell write the folowing command for each wsp file in the “WSP Solutions” folder ()
-          Add-SpSolution “WSP File Path” .
2.    Open the SharePoint 2010 Central Administration
3.    Click on the System Settings èManage Farm Solutions èclick on each WSP File and click on deploye link

Sunday, April 8, 2012

Recommendation 
try to use extended query web part in order to expose the  XSLT over the share point list

this link for shows some good libraries which are good for the share point developers
http://www.purecoding.net/CodeZone/SharePoint/tabid/67/ItemID/19/Default.aspx

Thursday, April 5, 2012

a great SharePoint blog

http://www.ahmadkhalaf.com/ahmadkhalaf/blog/?p=90
minimal master page in SharePoint
and here is a very good article


<%@ Master language=”C#” %>
http://www.w3.org/TR/html4/loose.dtd“>
<%@ Import Namespace=”Microsoft.SharePoint” %>
<%@ Register Tagprefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”Utilities” Namespace=”Microsoft.SharePoint.Utilities” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register Tagprefix=”WebPartPages” Namespace=”Microsoft.SharePoint.WebPartPages” Assembly=”Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
<%@ Register TagPrefix=”wssuc” TagName=”Welcome” src=”~/_controltemplates/Welcome.ascx” %>
<%@ Register TagPrefix=”wssuc” TagName=”DesignModeConsole” src=”~/_controltemplates/DesignModeConsole.ascx” %>
” runat=”server” xmlns:o=”urn:schemas-microsoft-com:office:office” __expr-val-dir=”ltr”>
<%– The head section includes a content placeholder for the page title and links to CSS and JavaScript files that run on the server. –%>
 </p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; line-height: 21px; color: rgb(109, 110, 110); font-family: Arial, Verdana, sans-serif; ">  <asp:ContentPlaceHolder id=”PlaceHolderPageTitle” runat=”server” /></p><p style="padding-top: 0px; padding-right: 0px; padding-bottom: 10px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-size: 12px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; line-height: 21px; color: rgb(109, 110, 110); font-family: Arial, Verdana, sans-serif; "> 

” id=”SiteActionsMenuMain” PrefixHtml=”<div><div>” SuffixHtml=”</div></div>” MenuNotVisibleHtml=”&nbsp;”>
            
            
              FeatureScope=”Site”
              Location=”Microsoft.SharePoint.StandardMenu”
              GroupId=”SiteActions”
              UseShortId=”true”
              >
             
               Text=”<%$Resources:wss,viewlsts_pagetitle_create%>”
               Description=”<%$Resources:wss,siteactions_createdescription%>”
               ImageUrl=”/_layouts/images/Actionscreate.gif”
               MenuGroupId=”100″
               Sequence=”100″
               UseShortId=”true”
               ClientOnClickNavigateUrl=”~site/_layouts/create.aspx”
               PermissionsString=”ManageLists, ManageSubwebs”
               PermissionMode=”Any” />
             
               Text=”<%$Resources:wss,siteactions_editpage%>”
               Description=”<%$Resources:wss,siteactions_editpagedescription%>”
               ImageUrl=”/_layouts/images/ActionsEditPage.gif”
               MenuGroupId=”100″
               Sequence=”200″
               ClientOnClickNavigateUrl=”javascript:MSOLayout_ChangeLayoutMode(false);”
               />
             
               Text=”<%$Resources:wss,settings_pagetitle%>”
               Description=”<%$Resources:wss,siteactions_sitesettingsdescription%>”
               ImageUrl=”/_layouts/images/ActionsSettings.gif”
               MenuGroupId=”100″
               Sequence=”300″
               UseShortId=”true”
               ClientOnClickNavigateUrl=”~site/_layouts/settings.aspx”
               PermissionsString=”EnumeratePermissions,ManageWeb,ManageSubwebs,AddAndCustomizePages,ApplyThemeAndBorder,ManageAlerts,ManageLists,ViewUsageData”
               PermissionMode=”Any” />
            
            
           

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 



Wednesday, April 4, 2012

Upload Document To Document Library with PUT method




Following is a utility function which you can use to upload a file programmatically in SharePoint document library. It has two parameters. First is the source file path and second is the target document library path. 
Following is an example call to this function:
UploadFileToDocumentLibrary(@”C:\test.txt”@”http://home-vs/Shared Documents/textfile.txt”);
and here is the function
    public static bool UploadFileToDocumentLibrary(string sourceFilePath, string targetDocumentLibraryPath)
    {
        //Flag to indicate whether file was uploaded successfuly or not
        bool isUploaded = true;
        try
        {
            // Create a PUT Web request to upload the file.
            WebRequest request = WebRequest.Create(targetDocumentLibraryPath);

            //Set credentials of the current security context
            request.Credentials = CredentialCache.DefaultCredentials;
            request.Method = “PUT”;

            // Create buffer to transfer file
            byte[] fileBuffer = new byte[1024];

            // Write the contents of the local file to the request stream.
            using (Stream stream = request.GetRequestStream())
            {
                //Load the content from local file to stream
                using (FileStream fsWorkbook = File.Open(sourceFilePath, FileMode.Open, FileAccess.Read))
                {
                    //Get the start point
                    int startBuffer = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length);
                    for (int i = startBuffer; i > 0; i = fsWorkbook.Read(fileBuffer, 0, fileBuffer.Length))
                    {
                        stream.Write(fileBuffer, 0, i);
                    }

                }
            }

            // Perform the PUT request
            WebResponse response = request.GetResponse();

            //Close response
            response.Close();
        }
        catch (Exception ex)
        {
            //Set the flag to indiacte failure in uploading
            isUploaded = false;
        }

        //Return the final upload status
        return isUploaded;
    }