Monday, September 17, 2012

Entity Framework 4


Getting Started with Entity Framework 4.0 Part 1
at you tube 

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;
    }

Tuesday, April 3, 2012

SharePoint Generic Webpart


public class BEATGenericWebPart : WebPart
{
    private string m_controlName;

    private string m_controlTemplatesPath;

    private string m_Folder;

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [WebDisplayName("Name of User Control")]
    public string ControlName
    {
        get
        {
            return this.m_controlName;
        }
        set
        {
            this.m_controlName = value;
        }
    }

    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    [WebDisplayName("Control Templates Path")]
    public string ControlTemplatesPath
    {
        get
        {
            return this.m_controlTemplatesPath;
        }
        set
        {
            this.m_controlTemplatesPath = value;
        }
    }

    [WebDisplayName("User Controls Folder")]
    [Personalizable(PersonalizationScope.Shared)]
    [WebBrowsable(true)]
    public string Folder
    {
        get
        {
            return this.m_Folder;
        }
        set
        {
            this.m_Folder = value;
        }
    }

    public BEATGenericWebPart()
    {
        this.m_controlTemplatesPath = string.Empty;
        this.m_Folder = string.Empty;
        this.m_controlName = string.Empty;
    }

    protected override void CreateChildControls()
    {
        try
        {
            string str = string.Format("{0}{1}{2}", this.m_controlTemplatesPath, this.m_Folder, this.m_controlName);
            Control control = this.Page.LoadControl(str);
            this.Controls.Add(control);
        }
        catch (Exception exception1)
        {
            Exception exception = exception1;
            Label label = new Label();
            label.Text = exception.Message;
            this.Controls.Add(label);
        }
    }

    protected override void RenderContents(HtmlTextWriter writer)
    {
        this.EnsureChildControls();
        base.RenderContents(writer);
    }
}

Wednesday, February 29, 2012

Accessing The DLL Files in GAC C:\Windows\assembly

There is a several way to access the DLL file which are located in the GAC (Global Assembly Cash), but one of the most easiest way is to access them through the access the path below

C:\Windows\assembly\GAC_MSIL

Ahmad Hindash

Monday, February 27, 2012

Sending data through rest service via generic handler ashx


REST Web Services in ASP.NET 2.0 (C#)

copy from the link http://www.codeproject.com/Articles/29706/REST-Web-Services-in-ASP-NET-2-0-C 

original author : 
Leo Stableford

Notes

  1. I have been informed that in .NET 3.5, there are smoother ways to do this. I do say that later in the article, but please be aware that this is a 2.0 only workaround. 
  2. I have had a warning that IIS6.0 doesn't like this workaround. I have only tried it on IIS 5.1 and it seemed fine. I shall be doing more testing when I can and I will let you know the results. RESULTS both IIS 6.0 and 5.1 require some tinkering to read URLs with no file extension. The 6.0 process can be found in the comments to this article. The 5.1 version requires the following steps: 
    • Open the website properties in IIS
    • Select the Home tab
    • Click the Configuration button
    • In new window select the Mappings tab
    • Click the Add button
    • In new window's executable field Browse to the ASP.NET ISAPI DLL (usually something likeC:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll)
    • In the Extension field, type .*
    • Untick the Check that file exists box and click OK 
N.B. There is a bug that if your OK button is not active, you need to click the executable field text box, you should see the middle section of the text in the box change from /.../ to the full file path.This should now make the OK button active.
Thanks to Neil Kilbride for that.

Introduction

Like so many people, I started out using SOAP Web requests which do integrate nicely into an IDE but they're not intuitive to the internet generation. A lot of people, Yahoo is one example, want their services to work in a way that any idiot could interpret or predict a likely behaviour. After all, if there's one thing you know you'll find on the internet it's any idiot.
So instead of pitching a great ball of SOAP to a server which then spits its own ball of SOAP back at you, we're going to take a look at REST.
If you really have to know REST stands for: Representational State Transfer.
I bet you feel better knowing that.
No. Maybe not.
I often find there's a dearth of brass tacks answers in Internet tutorials so if you've got this far I'll guess you are either familiar with or amenable to a Web request that is formatted...
www.someserviceprovider.com/myrestservice/3
... and which returns some handy chunk of XML or similar.
Yes. A REST request, when all is said and done, is a service which replaces your SOAP suds with a simple, common or garden URL.
It also just returns some XML or formatted text or whatever instead of a matching SOAP bubble. What could be simpler, put a URL into your address bar and unearth some juicy content.
Well, although it *is* simple from a user perspective, learning how to actually do it is another problem altogether.
What you're looking to do is implement an interface called IHttpHandler and the easiest way to get a working stub for this is to go to a Web project and add a new item of type generic handler (*.ashx file extension). When you do so, it will return a blank service that looks like this:
<%@ WebHandler Language="C#" Class="example" %>

using System;
using System.Web;

public class exampleRestService : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}
Basically you add your code into the "ProcessRequest" method and it can write something back to the screen, be that (as in this case) some text, or an XML document or whatever using its HttpContext object. As with any plain Web Request, what you submitted in the URL is a GET request and the only difference between this and visiting a website is that you are not requesting a file, you are requesting the current state of an object (i.e. a service).
However when you are using a generic handler harness the URL you would use to access it would be along the lines of:
www.someserviceprovider.com/exampleRestService.ashx
And it would do the rest.
So that is blatantly referring to a file, which is not as elegant as what we're wanting to do by implying in the very structure of our URL that there is no actual file to which we are referring.
However, while we have this acceptable yet clunky beast in front of us, let's make it do something when you prod it because it's easier to get your head round at this stage.
<%@ WebHandler Language="C#" Class="example" %>

using System;
using System.Web;

public class exampleRestService : IHttpHandler {
    
    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        string output = "";

        if (context.Request["input"] != null)
        {
                output = context.Request.QueryString["input"].ToString();
         context.Response.Write("Your Input Was: " + output);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
}
This basically means that when someone visits:
www.someserviceprovider.com/exampleRestService.ashx?input=hello%20world
Then the response they will get will be:
Your Input Was: hello world
So the effect is all great, but the execution leaves a little something to be desired. How do we grasp that subtly more pleasing URL format we were initially after?
The first thing you're going to have to do is start mucking about with your web.config file. The section you need differs depending on whether your IIS is 6.0 backwards or 7.0. If the latter, you're looking for a section called < handlers > in the < system.web > section. If the former, the section is in the same parent location but is now called < httpHandlers >.
The entry you want to put into the section looks like this:
IIS 6.0 and previous: 

IIS 7.0: 
The important attribute of this tag for our purposes is the one marked "type". Briefly I'll run through the rest:verb= will this be a handler for just GET? just POST? or both (*) so this one is both; path= what is the domain looking for in rerouting to this service? In this case, the path "exampleRestService/" and then anything from nothing to a single character to the text of your latest hilarious internet memo received via email (because even IIS needs a good laugh occasionally).
But then we get to the type attribute (Oh, IIS 7 people I don't run IIS 7 so what the name attribute does I'm not exactly clear on... names it? For some no doubt a wonderful benefit, I imagine.) What does it do? What magic does it perform? Well the first part before the comma tells it what namespace to look for and what class in that namespace it is trying to find. The part after the comma refers to the assembly it's going to look at.
I can see you all telling me to back up a few places here.
What assembly? I hear you ask. The one you are about to create I answer.
You see to do the URL handling you can't use the *.ashx file, it has to go. Sorry. Instead what you are going to do is start a new C# class library project. And for consistency with this article, you might call itMyWebServices.
Then in your class library, you might want to call your class exampleRestService.cs.
And it will look like this:
using System;
using System.Web;

namespace MyWebServices
{
 public class exampleRestService : IHttpHandler {
    
    public void ProcessRequest (HttpContext context)
    {
        context.Response.ContentType = "text/plain";

        string output = "";

        if (context.Request["input"] != null)
        {
                output = context.Request.QueryString["input"].ToString();
         context.Response.Write("Your Input Was: " + output);
        }
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }
 }
}
Yes, basically the ASHX without the ASP.NET header. Exactly.
Compile this out to a convenient location and then back in your Web project create a reference to the DLL you just compiled.
Now it all becomes clear, yes?
Well, no.
Because you'll still notice that to get the correct output, the URL has to be:
www.someserviceprovider.com/exampleRestService/?input=hello%20world
So close... yet not quite close enough.
We're literally "?input=" away from our goal. This problem would seem to be intractable. Apparently in .NET 3.5 or whatever the cool kids are calling it these days, there's some way of taking care of this automatically. I don't know, I'm still using 2.0.
All I know is that the probable best way to deal with this is to cheat.
Yes, you heard me. Cheat.
We all know that if you have input for a dynamic Web page, it should come in the form of GET or POSTvariables. That's fine but GET variables are always behind that dratted "?" and then you need each one to be tagged with a name like input which then "=" whatever you want to send.
If you have only one input variable, there's a way around this.
And here it is:
string output = "";
int subPos = 0;

output = context.Request.RawUrl.ToString();
if(output.IndexOf("/exampleRestService/") > -1)
{
        subPos = output.IndexOf("/exampleRestService/");
        subPos = subPos + 20;
 output = output.Substring(subPos);
}

context.Response.Write("Your Input Was: " + output);
Not exactly the most robust of solutions but, trust me, it works. It could be that you tuned out on me way back after I told you to start making class libraries and the like, but maybe you want to go that extra mile. If so, this is a way. I'd be keen to hear any better ideas as I'm not sure how robust this one would be in the long term.
For now though...
www.someserviceprovider.com/exampleRestService/the%20end
... will tell you that:
Your Input Was: the end