Thursday, January 21, 2021
Thursday, October 15, 2020
Share CDS record to a owner team or AAD team in Power Automate
Wednesday, June 11, 2014
Remote Event Receivers in SharePoint 2013
A new concept of remote event receivers have been introduced in SharePoint 2013.
These are similar to event receivers in 2010 except that they run remotely and not actually on server. Hence we user CSOM in the handlers.
There can be two type of event receivers
1. App event receivers
2. Remote event receivers.
Now we need to be clear that app event receivers and Remote event receivers work in Cloud Hosted App i.e. auto hosted or provider hosted. They do not work with SharePoint Hosted apps. I have seen some examples on net having remote event receivers on SharePoint Hosted app but event receivers are not meant for SharePoint Hosted App. There are some methods of these receivers to get client context and they dont work with SharePoint Hosted app. I had a tough time struggling with an event receiver on SharePoint Hosted app and then I stumbled on a line in msdn
Excerpt from MSDN
Note
Remote event receivers and app event receivers work only with cloud apps for SharePoint (that is, provider-hosted apps). These receivers don't work with SharePoint-hosted apps for SharePoint.
Source - http://msdn.microsoft.com/en-us/library/office/jj220048(v=office.15).aspx
How Does it work
Web services are used in remote event receiver.
When we add a remote event receiver to an app, a web service also gets added which handles these events.
Open Visual studio, Create a new project (App For SharePoint). I am going to select AutoHosted.
Now Add New List. Name the list “ListInApp”.
Now click add new item, Select Remote Event Receiver. It would ask for list name to be associated with. Select list just created ‘ListInApp’
Name it as AppListReceiver.
Next select “List Item Event” in type of event receiver. Select the list ListinApp that we just created. (Notice there are ItemAdding and ItemAdded, ItemDeleting and ItemDeleted and so forth)
I am going to select ItemDeleting and ItemAdded.
Notice AnnouncementReceiver.svc gets added in the solution explorer in the App Web project.
In the .svc file we notice there are 2 methods. ProcessEvent and ProcessOneWayEvent.
Now before we get into code let us look at the events
We can handle Before and After events. Now the Before events i.e. ItemAdding, ItemDeleting, etc are always synchronous while the after events i.e. ItemAdded, ItemDeleted etc can be synchronous as well as asynchronous
ProcessEvent handles the synchronous methods while ProcessOneWayEvent are one way, i.e. asynchronous. They just fired and are forgotten.
Notice I selected ItemDeleting and ItemAdded.
I am going to handle ItemDeleting to stop allowing to delete any items from my list.
| public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) if (properties.EventType == SPRemoteEventType.ItemDeleting) return result; } |
Similarly we can write code in ItemAdded even in the method ProcessOneWayEvent
Getting ClientContext in Remote Event Receivers.
Now to get client context there is a method available TokenHelper.CreateRemoteEventReceiverClientContext(properties)
Now a point to note here is the client context we get here is that of app web. That is because the event receiver is to handle events on a list on app web. If the event receiver is written to handle events of list on host web, the context returned is that of host web.
This brings the question how do we create remote event receiver to a list of host web. We do not get that option in Visual studio. This has to be done programmatically. Let us see how
Remote event receivers for list on host web
To do this I am going to write an app event receiver. My plan is to code an app. When this app gets installed, it add an event receiver to a list of host web.
Create a new app project for sharepoint. Select AutoHosted App.
Go to properties of the app and select the property “HandleAppInstalled” Set it to True
On doing so we will find AppEventReceiver.svc added to solution explorer in the appweb project
This would have method ProcessEvent
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
Further Below code can be self explanatory
| public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties) switch (properties.EventType) case SPRemoteEventType.AppUnInsstalled: HandleAppUninstalled(properties); break; return result; |
In HandleAppInstalled we will try to attach remote event receiver to host web’s list. Now to do this we need client context to host web.
SP gives us a magical method TokenHelper.CreateAppEventClientContext(properties,false)
If the second parameter of this method is false, it returns us the client context to host web else it returns us the client context to app web.
Note that this method is available only with App event receiver and when we try to use it with remote event receiver it returns null.
Below is the code
| private void HandleAppInstalled(SPRemoteEventProperties properties) using (ClientContext clientContext =TokenHelper.CreateAppEventClientContext(properties,false)) foreach (var rer in myList.EventReceivers) if (!rerExists) } } } |
The above code attaches event receiver to the MyAnnouncements list of host web. Now you must be wondering where do we write the event handler for this. If you closely observe the code we have given the Receiver url of the same class, hence we can write the event handler here itself.
The process event function of AppEventReceiver.svc gets changed to this
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
switch (properties.EventType)
{
case SPRemoteEventType.AppInstalled: HandleAppInstalled(properties);
break;
case SPRemoteEventType.AppUnInsstalled: HandleAppUninstalled(properties); break;
case SPRemoteEventType.ItemAdded: HandleItemAdded(properties); break;
}
return result;
}
We add a function HandleItemAdded and that would have the code what needss to be done when we an item is added to MyAnnouncements list.
Debugging
Last but not the least, how do I debug this app? To do this we can use Windows Azure service bus.
Steps from msdn (Source - http://msdn.microsoft.com/en-us/library/office/jj220047(v=office.15).aspx#DebugRER ) I tend to copy imp things on my blog as you never know which link breaks and goes down ;-)
To debug remote event receivers and app event receivers in an app for SharePoint, perform the following steps.
-
If you're behind a firewall, you may need to install a proxy client (such as the Forefront Threat Management Gateway (TMG) Client), depending on your company's network topology.
-
Register for a Microsoft Azure account if you haven't already, and then sign into that account.
For information about how to register for an Azure account, see Microsoft Azure.
-
Create an Azure Service Bus namespace, which you can use to debug remote events.
For more information about the Azure Service Bus, see Messaging and Managing Service Bus Service Namespaces.
Note
Remote event debugging uses the Relay Service component of the Azure Service Bus, so you'll be charged for using the Service Bus. See Service Bus Pricing FAQ. You get free access to Azure each month that you subscribe to Visual Studio Professional with MSDN, Visual Studio Premium with MSDN, or Visual Studio Ultimate with MSDN. With this access, you can use the Service Bus relay for 1,500, 3,000, or 3,000 hours, depending on your MSDN subscription. See Get some amount of Microsoft Azure Services each month at no additional charge.
-
In Azure, choose your service namespace, choose the Access Key link, and then copy the text in the Connection String box.
-
On the properties page of your app for SharePoint project, choose the SharePoint tab, and then select the Enable debugging via Microsoft Azure Service Bus check box.
You must enable this feature to debug remote events in cloud apps for SharePoint. This property applies to all of your SharePoint projects in Visual Studio. Visual Studio automatically turns off remote event debugging if you package your app for distribution on the Office store.
-
In the Microsoft Azure Service Bus connection string box, paste the connection string that you copied.
-
If you don't enable remote debugging and don't want to receive a notification whenever your project contains a remote event receiver or an app event receiver, clear the Notify me if Microsoft Azure Service Bus debugging is not configured check box.
After you enable remote event debugging and provide a valid connection string for the Azure Service Bus, you can debug remote events.
Note
If the remote event receiver doesn't hit a breakpoint immediately, the event might be asynchronous. Events that contain the word "being", such as "An item is being added" or "An item is being deleted", are synchronous and complete faster. Events that contain the word "was", such as "An item was added" or "An item was deleted", are asynchronous and take slightly longer to complete.
Request Management in SharePoint 2013
Why Request Management
SharePoint 2010 had request throttling. That is let us say been enhanced and in SharePoint 2013 we have Request Management.
Drawbacks of SP2010 Req Throttling
It was not possible to route specific requests to specific server i.e. that kind of control was not with the admin. For example if a particular WFE is down, the client gets server busy messages from the pool health WFE while other WFEs still were available.
Through RM we can plan to send specific requests to specific servers. E.g. all requests of specific type like search can be sent to specific machines.
RM can help maintain farm by sending heavy requests to powerful machines.
Through RM we can identify harmful requests
RM mainly includes following 3 main components
1. Request Routing
We have something called as Routing rules to route certain requests to certain WFEs. For e.g. an admin might decide to route all requests for .pdfs to WFE2. Routing rules can be written to serve this kind of request.
2. Request throttling and request prioritization
If a particular WFE is heavily utilized from one particular application e.g. Outlook sync is producing lot of sync requests. Now each machine has a health score from 0 to 10. 0 being the healthiest. An admin might decide to stop all requests from outlook sync when the health score of WFE reaches 8. Through RM, one can design a throttling rule which says to stop all requests from useragent *microsoftoutlook.* when the health score of the machine is 8.
3. Request load balancing
Select a WFE server to route the request based on the weighting scheme decided.
Now we need to be familiar with certain terms before understanding RM
1. Health score – We already saw this. Every WFE can get a health score between 0 and 8. The policy engine health rule updates the health weights and these cannot be changed by admin
2. Static weights – Each machine can be given a static weight by the admin. These again can vary from 1 to 10, 1 being the highest. Admin sets the static weights of the machines so that certain ones are always preferred
3. Routing weights – Routing weights uses health weights and static weights.
4. Routing Rules – Routing rules are configured by admin to route the requests of certain type to certain servers etc.
5. Throttling rules – Throttling rules are configured by admin to throttle certain kind of requests.
Routing and Throttling rules can match
| Matching Parameters | Methods |
| Url | Starts With |
| URL Referrer | Ends With |
| User Agent | Equals |
| Host IP | RegEx |
| Http Method | |
| Soap Action | |
| Custom Header |
One thing to note is Request Management is applied per web app.
How Does it Work
RM has execution groups. Execution groups contain routing rules. There are 4 execution groups. When a request comes, rules in execution group 0 are run. If any of the rule matches, the rest of the rules are not run. If none in Execution group 0 matches rules of the next execution groups are run. Each rule points to a machine pool. Each machine pool contains few servers. There are cmdlets to create machine pools and add servers to these. Each machines can be given static weights by admin. Again there are cmdlets for the same.
We need to start Request Management Service instance. This can be done from central admin by going to services of this server.
Powershell command ‘Start-SPServiceInstance’ can also be used for the same
1. SPRequestManagementSettings
Get-SPRequestManagementSettings – gets request management settings for a particular web application
Set-SPRequestManagementSettings – sets the settings for a web app
Example
$webApp = Get-SPWebApplication http://sharepoint01/
$rmSettings = $webapp | Get-SPRequestmangementsettings
Set-SPRequestManagement Settings can be used to set few configurable properties like ThrottlingEnabled.
Example -
$webapp | Set-SPRequestManagementSettings -ThrottlingEnabled $True
The RequestManagementSettings object got through Get-SPRequestManagementSettings is passed to other cmdlets of RM
2. SPRoutingMachinePool
Cmdlets – Add-SPRoutingMachinePool – allows to add machine servers to a pool and also create a machine pool
Get-SPRoutingMachinePool – allows to get a machine pool configuration.
Example -
Add-SPRoutingMachinePool -Name `PrimaryMachinePool' -RequestManagementSettings $rmSettings -MachineTargets "SPTaleSpin2013"
Get-SPRoutingMachinePool –RequestManagementSettings $rmSettings
3. SPRoutingMachineInfo
CmdLets – Get-SPRoutingMachineInfo – gets machine info
Set-SPRoutingMachineInfo – allows to set properties like static weight for a particular machine.
Example
$machineInfo = Get-SPRoutingMachineInfo –Name “SP02” –RequestManagementSetting $rmSettings
Set-SPRoutingMachineInfo –Identity $machineInfo –StaticWeight 4
4. Add-SPRoutingRule and Add-SPThrottlingRule
As the name suggests these cmdlets are used to add routing and throttling rule.
Each of the routing or throttling rule needs a criteria.
New-SPRequestManagementRuleCriteria – cmdlet lets us define a criteria. This cmdlet has 3 params
a)Property – It can be Url, Url Referrer, UserAgent (all the parameters we saw in the table above)
b)MatchType – It can be Equal, StartsWith, Regex (all the methods we saw in the table above)
c)Value – The value of property to be matched with
Example
$criteria1 = New-SPRequestManagementRuleCriteria –Property Host –MatchType Equals –Value “www.abc.com”
Hence criteria1 is all request for host www.abc.com
Now lets create a routing rule
$webApp = Get-SPWebApplication ‘http://sp1”
$rmSettings = Get-SPRequestManagementSettings $webApp
$mp1 = Get-SPRoutingMachinePool –RequestManagementSettings $rmSettings –Name “primary machine pool”
$criteria1 = New-SPRequestManagementRuleCriteria –Property Host –MatchType Equals –Value “www.abc.com”
$rule1= Add-SPRoutingRule –RequestManagementSettings $rmSettings –Name ‘Rule for abc.com’ –Criteria $criteria1 –ExecutionGroup 0 –MachinePool $mp1
Similarly we can define throttling rule as
$criteria2 = New-SPRequestManagementRuleCriteria –Property UserAgent –MatchType Regex –Value ‘*.microsoft.outlook.*’
Add-SPThrottlingRule –Criteria criteria2 –Threshhold 8
Monday, June 9, 2014
Caml Queries
Everytime I start writing CAML I fall back to U2U.
Wanted to keep few queries handy so here we go
No Filter
<View><ViewFields><FieldRef Name="Title" /><FieldRef Name="Column2" /></ViewFields></View>
With Row Limit
<View><RowLimit>10</RowLimit><ViewFields><FieldRef Name="Title" /><FieldRef Name="Column2" /></ViewFields></View>
Above two can be used with CamlQuery object as view xml.
example
CamlQuery camlquery = new CamlQuery();
camlquery.ViewXml = "<View><RowLimit>10</RowLimit><ViewFields><FieldRef Name='Title'/><FieldRef Name='FileRef'/><FieldRef Name='BasePath'/></ViewFields></View>";
List sSCConfigList = clientContext.Web.Lists.GetByTitle("SSCConfig");
clientContext.Load(sSCConfigList);
clientContext.ExecuteQuery();
var listItems = sSCConfigList.GetItems(camlquery);
Single Select
Example
<Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">ABC VALUE</Value></Eq></Where></Query>
Multiple Rows
Example
<Query><Where><Contains><FieldRef Name="Title" /><Value Type="Text">Some Text</Value></Contains></Where></Query>
In case of Rich Text field, you can use <![CDATA[]]> around the value to prevent parsing errors when passing HTML into the query. Or you can replace < with <, > with > and “ with " and so on.
Other operators are <Geq/> for greater than and <Leq/> for less than
LookUps
Here we use LookupId=”true”. By using this we can specify the id value in the value tag
Look up on Id
example
<Query><Where><Eq><FieldRef Name="SomeLookupcolumn" LookupId="TRUE" /><Value Type="Lookup">4</Value></Eq></Where></Query>
Here It will filter on ‘SomeLookupColumn’ column here based on look up id and not value. This ensures unique value.
This can be used to get person or group also
example
Filter on Current User
Example
<Query><Where><Eq><FieldRef Name="Author" LookupId="TRUE" /><Value Type="Integer"><UserID /></Value></Eq></Where></Query>
Notice here Valuetype is integer.
Using <UserID /> as the value, the query will filter based on the current user. You can also pass the ID of a specific user in place of <UserID /> (e.g. <Value Type="Integer">283</Value>) if you don’t want to filter by the current user.
Lookup on text
Example
<Query><Where><Eq><FieldRef Name="SomeLookupColumn" /><Value Type="Lookup">GujaratState</Value></Eq></Where></Query>
This will look for items with “GujaratState” in the look up column field. If there are more than one items having same display name, it will return all those items.
Date & Time
Example
<Query><Where><Eq><FieldRef Name="Modified" /><Value Type="DateTime"><Today /></Value></Eq></Where></Query>
A date can also be used instead in Value tag. We can also use something like this <Today OffsetDays="-4" />
Friday, May 23, 2014
How to check if your server is connected to DC
First add a AD DS feature from server manager.
Once done run the command
DCDIAG /TEST:DNS /V /E /S:domaincontroller
where domain controller is the name of your domain e.g. contoso.com
Saturday, May 10, 2014
System.Runtime.InteropServices.COMException: <nativehr>0x81072101</nativehr><nativestack></nativestack>Cannot complete this action.
I created a SharePoint hosted app. The app had some site columns and a list including these columns.
I struggled with this error for some time. Removing the list and the app would deploy just fine. I realized one site column had space in name. The name of column for e.g “Expense Amount”. Adding this column to the list would give this error. So I added a new column this time the name was “ExpenseAmount” and display name would be “Expense Amount” and it worked just fine.
Another observation was the Type in my case was 10000. As a rule I changed it to 10002 and I started getting the error again. Changing it back to 10000 and it worked fine. Still not sure of the real cause but thought to put the observations here just in case it myt save someone’s time.
Friday, May 9, 2014
Host named site collections in SharePoint 2013
What are HNSC
Traditional site collections that we create in SharePoint are Path based site collections
Host named site collections have their own url.
Example
Microsoft recommends using host named site collection. It is used in SharePoint online and Office 365.
Benefits of HNSCs
A SharePoint farm can have 20 web applications at max. If we use path based site collections in order to have unique urls we need to create different web applications with different host names.
For example if we need to create following site collections
By using path based site collections we need to create 3 web application with appropriate host names.
But by using host named site collections we can create one web application and 3 site collections with different urls.
Path based site collection are not scalable as we can create at max 20 web applications, while a sharePoint farm can have at max 250000 site collections using shared content database.
When to use Path Based site collections
1. You want separate application pools.
2. You have requirement of self service site creation feature. - You need to use a custom solution for self-service site creation with host-named site collections.
How to create HNSC
HNSC can be created only through powershell script
- Create web application
- Create root site collection (required for crawling)
- Create host named site collections
- Set alternate URLs for host named site collection
Let us have a closer look.
- Create a web application (either through central admin or through powershell).
I created through central admin
port – 100
Web app name – SharePoint – 100
- Now create a root site collection. When root site collection is crawled, all HNSC s also get crawled although they do not appear in content sources
New-SPSite 'http://<servername>:100' -Name 'Root Portal' -Description 'Root site collection' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'STS#0'
- Now create HNSC. Use following powershell to create HNSC
New-SPSite 'http://CompanyA.contoso.com:100' -HostHeaderWebApplication 'http://<servername>:100’ -Name ‘CompanyA portal’ -Description 'Portal for CompanyA' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'BLANKINTERNET#0'
New-SPSite 'http://CompanyB.contoso.com:100' -HostHeaderWebApplication 'http://<servername>:100’ -Name ‘CompanyB portal’ -Description 'Portal for CompanyB' -OwnerAlias 'contoso\administrator' -language 1033 -Template 'BLANKINTERNET#0'
Managed paths with host-named site collections
Managed paths can be used with host-named site collections. Managed paths for HNSC are different from path based site collections. Managed paths for HNSC are available to all HNSCs in the farm regardless of the web application. They are limited to 20 per farm. While managed paths for path based site collection do not apply to path based site collectioins in other web applications.
To create managed path for HNSC we need to use powershell
New-SPManagedPath ‘dept’ –HostHeader
Now we can create HNSC with managed path
New-SPSite ‘http://CompanyA.contoso.com:100/dept/Technology’ –HostHeaderWbApplication ‘http://<servername>:100’ –Name ‘Technology’ –Description ‘Technology department’ –OwnerAlias ‘contoso\administrator’ –language 1033 –Template ‘BLANKINTERNET#0’
Managed path for path based site collection can be defined at central admin or using powershell
New-SPManagedPath [-RelativeURL] "</RelativeURL>" -WebApplication <WebApplication> creates managed path for a particular web application that can be used by path based site collections of that particular web application
Having done this you can check by browsing the site
Note : – In case you see a 404 error and if you are browsing the site on same local SharePoint server, you would need to change the host file to include then entry
for example to browse http://companyA.contoso.com:100 the entry in host file would be
127.0.0.1 companyA.contoso.com
Further you need to disable LoopBack in registry. To do this manually open registry using regedit and nav to HKEY_LM\System\CCS\Control\LSA
Create dword key with name ‘DisableLoopbackCheck’. Change the value to 1 for this.
It can also be done using powershell
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -Value "1" -PropertyType dword
Wednesday, December 4, 2013
Get crawled property name for your column
I was desperately trying to find what is the crawled property name of my column scheduling end date.
I stumbled across this helpful powershell
Function Get-CrawledPropertyNames([string]$DocURL){
$DocURL = $DocURL.Replace("%20"," ")
$webfound = $false
$weburl = $DocURL
while ($webfound -eq $false) {
if ($weburl.Contains("/")){
$weburl = $weburl.Substring(0,$weburl.LastIndexOf("/"))
$web = get-spweb -identity $weburl -ea 0
if ($web -ne $null){
$webfound = $true
}
}else{
Write-Host -ForegroundColor Red "The Web could not be found"
return -1
}
}
$web.GetFile($DocURL).item.xml.Replace("' ", "' `n").Replace("`" ", "`" `n")
}
#To use enter the url of a file within a doucment library Get-CrawledPropertyNames http://sites/doc/file.pdf
Got it from this link.
http://gallery.technet.microsoft.com/scriptcenter/Get-Crawled-Property-names-9e8fc5e0
Wednesday, October 2, 2013
Creating your own VHD for SP2013
Go to Hyper-V.
Click New VHD.
After installing basic OS we need to install AD.
Using following link install AD.
Open Server Manager. To open Server Manager, click Start, point to Administrative Tools, and then click Server Manager.
In Computer Information, click Configure Remote Desktop.
In the System Properties dialog box, under Remote Desktop, click one of the following options:
- Allow connections from computers running any version of Remote Desktop (less secure). Use this option if you do not know the version of Remote Desktop Connection that will be used to connect to this server.
- Allow connections only from computers running Remote Desktop with Network Level Authentication (more secure). Use this option if you know that the users who will connect to this server are running Windows Vista or Windows Server 2008.
Review the information in the Remote Desktop dialog box, and then click OK twice.
Make sure to give 2 processors
Wednesday, July 24, 2013
AD and SharePoint users sync
Lot of times we encountered the problem where for testing we add users in AD and they do not get access to site the same time and even after doing User Profile Synchronization job run, we could not solve the problem.
Turns out the below blog helped.
http://blog.randomdust.com/index.php/2013/06/sharepoint-2013-claim-expiration-and-ad-sync/
Wednesday, June 19, 2013
Page cannot be displayed error while creating Web application
While creating a new web application, a 404 'Page not found' error is displayed and the web application is only provisioned on the local server
After a number of web applications have been created in the SharePoint 2010 farm, further attempts to create a new web application through Central Administration result in the following:
The creation process results in a 'Page cannot be displayed' message.
The web application is only provisioned on the Central Administration server.
But if you try to create a site collection on this newly created web app, it fails. Reason is it is not completely done.
After struggling this for a while I found you can resolve by increasing the Shutdown time limit in IIS to a greater value.
Steps
- Go to application pool of Central Administration.
- Right click on it and go to Advanced Settings
- In the Process Model section, increase the shutdown time limit to 200 for example.
- It is a good idea to restart IIS now.
- After searching on net for a while I found that the reason is during the web application creation process IIS is reset and by default. It allows the "Shutdown time limit" which by default is 90 seconds. Sometimes this might not be enough. And hence it forcibly shuts down in 90 seconds.
Saturday, June 1, 2013
Open web.config file
1. C:\inetpub\wwwroot\wss\virtualdirectories\
a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true
2.If still you are facing default error page then follow below change
In the layouts directory underneath the SharePoint root directory or 14 hive – C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS
a. In customErrors tag set mode="Off" to "On
b. In SafeMode tag set CallStack="true" to false
c. In Compilation tag Debug="false" to true
Wednesday, July 18, 2012
Turning off custom errors in for debugging in SharePoint 2010
As a developer, one of the first things I do after I have setup a web application & site collection is:
Open the web.config (“C:\inetpub\wwwroot\wss\VirtualDirectories\(port)”) and set:
1.change batch and debug to true - (compilation batch="true" debug="true" )
2.change CallStack=”true” in safe Mode tag - (SafeMode CallStack="true")
3.Change CustomErrors=”Off”
However when I ran into exception, instead of getting the detailed message I was expecting, I ended up getting the infamous message telling me to change the customerrors setting in the web.config so that I can see the details:
Server Error in '/' Application.
After embarassingly long time I figured out there is another web.config in _layouts directory - C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14
Custom errors need to be turned off here too.
Friday, June 3, 2011
MVC vs MVP
Friday, February 4, 2011
Writing an Extender Control
This location below has a powerpoint presentation and a zip with a demo code.
The power point presentation talks some basics about Microsoft Ajax Library key components and the demo shows how to make an extender control.
Please remember to select extender control template while creating extender control in Visual studio. It will save you lot of configuration lines that you might have to write otherwise.
https://docs.google.com/leaf?id=0B_ZpzrhCCVOoNTE0N2ZkMDktNWQ5Yy00ZTIwLTg4ZTAtY2Y5YjE0ODEyYTYy&hl=en&authkey=CIqq8CQ
Tuesday, December 28, 2010
Ajax Library – Event Handling
System.ComponentModel.EventHandlerList - to add custom events to an object
To add custom events to an object, you add an instance of Sys.EventHandlerList into another object and expose public methods off that object that manipulate the instance. (Table 2.5 details the methods we use to manipulate the Sys.EventHandlerList type.)
How to add a custom event.
For instance I have an array notes[]. When I add a note I want to add an event, that shows an alert. To do this
1. Create an instance of Sys.Event.HandlerList. This instance holds list of handlers with their associated events.
_events=new Sys.EventHandlerList();
_events.addHandler("noteadded", functionName);
addHandler method adds the event name and function name to be executed on raise of that event.
How to raise this custom event
For this whenever a note is added following code needs to be written
var handler= _events.getHandler("notedded");
If(handler!=null)
handler(this,Sys.EventArgs.Empty)
2. To pass arguments of your own you need to create a class and inherit from Sys.EventArgs
Example
NotebookNamespace.NoOfNotesEventArgs=function(numOfNotes)
{
This._noOfNotes=numOfNotes;
}
NotebookNamespace.NoOfNotesEventArgs.prototype= {
Get_noOfNotes : function()
{
return this.noOfNotes;
}
}
NotebookNamespace.NoOfNotesEventArgs.registerClass("NotebookNamespace.NoOfNotesEventArgs", Sys.EventArgs)
Another this worth mentioning here is Sys.UI.DomEvent.
The Sys.UI.DomEvent class provides cross-browser access to DOM element event properties and methods to work with DOM element events
Some familiar methods of this class are $addHandlers, clearHandlers, preventDefault etc
Example
Var btn=$get("button1");
$addHandler(btn,{"click":button1_clickHandler});
However this has a problem of maintaining scope. The example below will tell you what I mean.
<html>
<body>
<form id="form1" runat="server">
<input type="button" value="btnTest" id="test" />
<asp:ScriptManager ID="scrptMgr" runat="server" />
</form>
<script type="text/javascript">
MyObject = function() {
this._name = "Deepa";
};
MyObject.prototype = {
clickEventHandler: function(e) {
alert (this._name);
}
};
var myObject = new MyObject();
$addHandler($get("btnTest"), "click", myObject.clickEventHandler);
</script>
</body>
</html>
The code looks like it will alert "Deepa". But it alerts "undefined"
That is because when event handler clickEventHandler executes, this points to the testButton and not the class MyObject.
To correct this we use Delegate provided by Microsoft Ajax Library
To create the delegate, we use the Function.createDelegate method, as
follows:
var del = Function.createDelegate(<instance>, <methodName>);
In the evenHandler i.e. <methodName> here, this will refer to <instance>
Hence with below code, "Deepa" will be alerted when clickEventHandler is executed
var myObject = new MyObject();
var dele =Function.createDelegate(myObject, myObject.clickEventHandler);
$addHandler($get("btnTest"), "click", dele);
Tuesday, November 30, 2010
.Net Framework 4.0 – What’s new
What are the major improvements provided by the common language runtime and the base class libraries?
Brief about the Improvements -
Diagnostics and Performance - Starting with the .NET Framework 4, you can get processor usage and memory usage estimates per application domain.
Garbage Collection - This feature replaces concurrent garbage collection in previous versions and provides better performance.
Code Contracts - Code contracts let you specify contractual information that is not represented by a method's or type's signature alone. The new System.Diagnostics.Contracts namespace contains classes that provide a language-neutral way to express coding assumptions in the form of preconditions, postconditions, and object invariants.
Design-Time-Only Interop Assemblies - You no longer have to ship primary interop assemblies (PIAs) to deploy applications that interoperate with COM objects. In the .NET Framework 4, compilers can embed type information from interop assemblies, selecting only the types that an application (for example, an add-in) actually uses.
Dynamic Language Runtime - The dynamic language runtime (DLR) is a new runtime environment that adds a set of services for dynamic languages to the CLR. The DLR makes it easier to develop dynamic languages to run on the .NET Framework and to add dynamic features to statically typed languages. To support the DLR, the new System.Dynamic namespace is added to the .NET Framework.
Covariance and Contravariance - Several generic interfaces and delegates now support covariance and contravariance.
BigInteger and Complex Numbers - The new System.Numerics.BigInteger structure is an integer data type that can store fairly large number as it has no upper and lower bound values.Complex types represents a complex number of form a + bi. IT supports arithmetic and trigonometric operations with complex numbers.
Tuples - The .NET Framework 4 provides the System..::.Tuple class for creating tuple objects that contain structured data.
File System Enumeration Improvements - You can now enumerate directories and files by using methods that return an enumerable collection of strings of their names.ou can also use methods that return an enumerable collection of DirectoryInfo, FileInfo, or FileSystemInfo objects.
Memory-Mapped Files - A memory-mapped file contains the contents of a file in virtual memory and is an application’s logical address space. So You can use memory-mapped files to edit very large files and to create shared memory for interprocess communication.
64-Bit Operating Systems and Processes - You can identify 64-bit operating systems and processes with the Environment.Is64BitOperatingSystem and Environment.Is64BitProcess properties.
Pasted from <http://www.dotnetcodes.com/dotnetcodes/code/Articles-55-Net-framework-40-major-improvements.aspx>
Monday, November 15, 2010
My 2 hour weekend experience after the weekend
I have already given up doing tasks that I consider NECESSARY, however to finish out "THE ABSOLUTELY NECESSARY" tasks of the day like brushing my teeth, taking bath etc I get up early on the weekend so that I am done by the time she is awake.
By being so demanding of me, she actually makes me feel so very special. All she wants is her MOMMMYYYY and I feel so loved so much wanted for and so nice :). And so Sunday night I am totally exhausted, my left forearm, the region near Ulna gets swollen and my feet are on fire.
No doubt the Monday blues get worse for me. And I really need lot of will to start for office. Today was no different "Monday" and my hubby down with fever adding to the "BLUES". On my way to office an inner voice told me hey Super Women (I consider all working mothers super women) you need a break too!!!! You deserve a VACATION. And I was like OKK!!!... but is there something that can give me a VACATION experience in 2 hrs (an affordable time I could be out of office)??.....Inner voice answers - A SUPERB SPA ......My heart jumped and my car took a left turn for the parlor.... A WOW Experience :).....
A message to all superb women ... Listen to your inner voice, find time for yourself and get a WOW experience :)
Thursday, September 23, 2010
Strategy Pattern
So here are the links
Presentation
Code
MVP Design pattern demo links
MVP demo code
Happy Learning




