Friday, August 31, 2012

Share Point application pool re-set for perticular user and page.

It was very frustrating, In one of our production site, only two members of Management group when goes to view a particular web part page, browser do not open and IE (version 9.0) gave, "Internet explorer can not display this page."

In FireFox it returned a co-relation token ID searching that toke returned following few logs

"Usage Logging Importer: Exception occured while retrieving profiling information for the user="

"Microsoft.Office.Server.UserProfiles.UserNotFoundException: An error was encountered while retrieving the user profile."

"System.TimeoutException: The HTTP request to 'http://server:xxxxx/GUID/MetadataWebService.svc' has exceeded the allotted timeout of 00:00:09.9990000. The time allotted to this operation may have been a portion of a longer timeout. ---> System.Net.WebException: The operation has timed out     at System.Net.HttpWebRequest.GetResponse()"

"System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:      at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)     at Microsoft.SharePoint.Taxonomy.IMetadataWebServiceApplication.GetServiceSettings(Guid rawPartitionId) "

"'http://server:xxxxx/GUID/MetadataWebService.svc' Channel: 'System.ServiceModel.Channels.ServiceChannel' Action: 'http://schemas.microsoft.com/sharepoint/taxonomy/soap/IMetadataWebServiceApplication/GetServiceSettings' MessageId: 'urn:uuid:"

It was clear that something authentication or operation timeout is taking place, but was not clear why as I am not that much expert... So I decided to monitor Application log which gave me, following

"Log Name:      Application
Source:        Application Error
Date:         Date:Time 
Event ID:      1000
Task Category: (100)
Faulting application name: w3wp.exe, version: 7.5.7601.17514, time stamp: 0x4ce7afa2
Faulting module name: KERNELBASE.dll, version: 6.1.7601.17625, time stamp: 0x4de88429
Exception code: 0xe053534f
Fault offset: 0x000000000000cacd
Faulting process id: 0x%9
Faulting application start time: 0x%10
Faulting application path: %11
Faulting module path: %12
Report Id: %13

 w3wp.exe
    7.5.7601.17514
    4ce7afa2
    KERNELBASE.dll
    6.1.7601.17625
    4de88429
    e053534f
    000000000000cacd"

While the  System Event log gave me following entries.

"Log Name:      System
Source:        Microsoft-Windows-WAS
Date:          DateTime
Event ID:      5009
Task Category: None
Level:         Warning
Keywords:      Classic
User:          N/A
 A process serving application pool 'SharePoint - port' terminated unexpectedly. The process id was '3612'. The process exit code was '0x800703e9'.

SharePoint - port
    3612
    800703e9

 

Log Name:      System
Source:        Microsoft-Windows-WAS
Date:          Date Time
Event ID:      5011
Task Category: None
Level:         Warning
Keywords:      Classic

A process serving application pool 'SharePoint - port' suffered a fatal communication error with the Windows Process Activation Service. The process id was '6824'. The data field contains the error number. 

 SharePoint - port
    6824
    6D000780"


So much logs and googling each gave hundreds of solution. I was really out of directions where to go... I tried may things like

changing local server security options for Network logon, re creating application pool, synchronizing User Profile service multiple times successfully, changing application pool Identity, add user to Farm Admin, making SQL server dbo, etc., etc.,  then I found one post here which told to trace the code, I decided to go for it,

http://stackoverflow.com/questions/9695339/application-pool-crashing

I changed the code and put trace log at almost each alternate line, nothing unusual, but though after one particular spot it stopped to execute and RE_SET then application pool.. I notice that part of code and found that it was about querying and filtering a table view with long filter string, AND I have very limited physical memory on my web front end server having only 4GB on PROD server !!! increasing memory instantly was not feasible, So I changed logic to avoid long query and filtering in memory table, go with loops and filtering, and it worked !!!

OVER ALL (SharePoint, Dot Net, c#) ::: Application pool reset caused stop rendering particular web part page to particular users only. In web part code, a long filtering and querying in memory table (any lengthy or bulky in memory operation on inmemory object)  pushed system KERNELBASE and as result system reset your application's application pool :) (tit for tat !!) and users think that you have played with their profiles and permissions... :)

HOPE This HELPS SOMEONE as ME...

Friday, July 27, 2012

User can not be found Error Exception in Sharepoint Designer Workflow Publishing

While doing same changes which tested on UAT on a SharePoint production server I found error "User can not be found"
While publishing the workflow,
While clicking on list workflow settings
And While Activating "Workflows" Site collection feature.

Googling through various options I couldn't succeeded then I thought can I import SPD WF from one Farm to other FARM ? and I found following which saved my weekend :)

https://chanakyajayabalan.wordpress.com/2012/01/02/copyingmoving-sharepoint-2010-designer-workflows/

POINTS TO READ : 
1)) I had to re-publish all SPD and Reusable WFs.
2)) I didn't activated claims authentication.
3)) In all workflows variables of lookup type I had to manually re-set. Importing WF lost lookup and showed GUID only.

May be helpful to someone...


Thursday, June 7, 2012

ASP.Net Tree view check uncheck problem.

Recently I faced issue to check UN-check tree view nodes of a multilevel tree bound with SharePoint document library structure. I searched google but could not found any easy solution so decided to resolve it simply on my own. I wrote "TreeNodeCheckChanged" event. From it I called a recursive function.

  private void CheckUnCheck(TreeNodeEventArgs e)
        {
            if (e.Node.ChildNodes != null && e.Node.ChildNodes.Count > 0)
            {
                foreach (TreeNode childNode in e.Node.ChildNodes)
                {
                    if (e.Node.Checked)
                    {
                        if (!childNode.Checked)
                            childNode.Checked = true;                       
                    }
                    else
                    {
                        if (childNode.Checked)
                            childNode.Checked = false;
                    }
                    if (childNode.ChildNodes != null && childNode.ChildNodes.Count > 0)
                    {
                        CheckUnCheck(new TreeNodeEventArgs(childNode));
                    }
                }
            }
        }
this is not done yet. This function wont fire (I don't know why...) so I used a simple trick in Client side called a javascript function like below.

function CheckChangeEvent(event) {
        var obj = null;
        if ((navigator.appVersion.indexOf("MSIE 7.0") > 0) || (navigator.appVersion.indexOf("MSIE 8.0") > 0)) {
            obj = window.event.srcElement;
        }
        else {
            obj = event.target;           
        }
        if (obj == null) {
            alert('Object not found!');
            return false;
        }           
        if (obj != null) {
            if (obj.tagName == "INPUT" && obj.type == "checkbox") {
                __doPostBack(obj.id, '');
            }
            return true;
        }
        else {
            return false;
        }
    }

It do as post back on each click but does the trick... Hope this will help someone.

Wednesday, March 14, 2012

Export data table to Excel

To Export Data table to excel

following code can be useful


SPContext context = SPContext.Current;
System.Web.HttpResponse currentResponse = this.Response;
foreach (DataColumn column in table.Columns)
{
currentResponse.Write(column.ColumnName + "\t");
}
currentResponse.Write(Environment.NewLine);
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++) { currentResponse.Write(row[i].ToString().Replace(";", string.Empty) + "\t"); } currentResponse.Write(Environment.NewLine); } currentResponse.ContentType = "text/xls"; currentResponse.AppendHeader("Content-Disposition", "attachment; filename=" + name + ".xls"); currentResponse.End(); currentResponse.Close();
HOPE THIS HELPS SOMEONE

Export Nested SPGridViews to Excel

I spend entire day to resolve bugs for rendering HtmlTextWriter to excel in a visual web part, for each solution you need to modify either web.config or @page directive or override VerifyRenderingInServerForm method on page... It started to spinning my head, then I thought to do something by my own...

1) On ClientClick of link/image/button find GirdView's innerHTML
2) Assign that innerHTML to a hidden field
Add following code to your serverside event

System.Web.HttpContext curContext = System.Web.HttpContext.Current;
curContext.Response.Clear();
System.IO.StringWriter strWriter = null;
System.Web.UI.HtmlTextWriter htmlWriter = null;
curContext.Response.Clear();
curContext.Response.Buffer = true;
curContext.Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode("YOURFILE", System.Text.Encoding.UTF8) + ".xls");
curContext.Response.ContentType = "application/vnd.ms-excel";
curContext.Response.Write('>meta http-equiv=Content-Type content=text/html;charset=UTF-8<');
strWriter = new System.IO.StringWriter();
htmlWriter = new System.Web.UI.HtmlTextWriter(strWriter);
htmlWriter.Write(">TABLE Gridline=\"Both\"<");
htmlWriter.Write(hdnGridInnerHTML.Value.ToString());
htmlWriter.Write(">/TABLE<");
curContext.Response.Write(strWriter.ToString());
curContext.Response.Flush();
curContext.Response.End();

THERE is one Problem still I am facing... If any body can help.
If you open this document it won't show you correctly. BUT if you Save it locally and then open it opens correctly...

HOPE THIS MIGHT HELP SOMEONE

Limit Sharepoint Site Search with Current SPSite Object

Previously I tried a lot to limit my site search within the local site but could not succeeded.

If you want to create a simple site search utility in your web part page.

I found useful link at HERE, Thanks to Josh...

I created a visual web part and added following code


<script language="javascript" type="text/javascript">
function RedirectToSearchResultsPage() {
var searchVal = document.getElementById('SearchTerm').value;
window.location = "searchresults.aspx?k=" + searchVal + "&cs=This Site" + "&u=<%= SPContext.Current.Site.Url %>"; } </script> <div class="listDiv"> <table width="100%"> <tr> <td> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="left" class="listTitle-tms"> Search Site </td> </tr> <tr> <td> <input id="SearchTerm" style="width: 70%" /> <input type="button" onclick="RedirectToSearchResultsPage()" value="Search" /> </td> </tr> </table> </td> </tr> </table> </div>


(REMOVE br Tags)
Hope you find it useful.