Wednesday, May 30, 2012

Get currency value from a string contains $

Here is a quick way to get the currency value from a string which contains "$" and ",".

Some  may struggle to remove the "$" and  ","

but here is the way

Double pdblValue = Double.Parse("$96,000.00", NumberStyles.Any);


it needs a reference to "System.Globalization"  namespace

A Web Part with this ID has already been added to this page

Recently I was playing with adding webparts programatically.

Then I got this error "A Web Part with this ID has already been added to this page"

tried to use contents=1, but no use . it says page could not found

finally found the below link

http://dpruna.blogspot.com/2011/11/web-part-with-this-id-has-already-been.html

Thanks to author.


using the following procedure we can find out the webparts added to the given page.

Note:- it contains webparts added by all the users. (Not only you)

it gives you list of webparts added to that page (problamatic duplicate webparts aswell). Then you know what to do.

delete the webpart wisely

if it is dev server then may be less issues, but if it is Production server.........be careful

Here is the procedure.

Note:- My list exists in subsite ("ABC"). So I had to use @DocDirName = N'ABC/Lists/Raportari',


declare @DocDirName nvarchar(255),
        @DocLeafName nvarchar(255),
        @SiteId uniqueidentifier,
        @DocId uniqueidentifier,
        @DocParentId uniqueidentifier,
        @Level int
 
select  @SiteId = '88501D83-5339-4745-827F-0C7454F9B7BD',
        @DocDirName = N'Lists/Raportari',
        @DocLeafName = N'EditForm.aspx',
        @Level = 1
 
SELECT TOP 1  
    @DocParentId = ParentId,  
    @DocId = Id  
FROM  
    TVF_Docs_NoLock_Url(@SiteId, @DocDirName, @DocLeafName) AS Docs  
 
SELECT  
    WP.tp_ID,  
    WP.tp_WebPartTypeId,  
    WP.tp_Assembly,  
    WP.tp_Class,
    WP.tp_SolutionId,  
    WP.tp_AllUsersProperties,    
    WP.tp_WebPartIdProperty,
    WP.tp_Version,  
    WP.tp_Cache,  
    (N'{' + CAST(WP.tp_ListId AS nvarchar(36)) + N'}') AS tp_ListId,  
    WP.tp_Type,  
    WP.tp_Source,  
    WP.tp_BaseViewID,  
    WP.tp_View,  
    WP.tp_CreationTime  
FROM  
    AllWebParts AS WP WITH (INDEX=PageUrlID_FK)
WHERE  
    tp_SiteId = @SiteId AND  
    tp_IsCurrentVersion = CONVERT(bit, 1) AND  
    tp_PageUrlID = @DocId AND  
    tp_PageVersion = 0 AND  
    tp_Level = @Level

Wednesday, May 23, 2012

remove user from sharepoint group

The trick is

SPUser user = web.EnsureUser(peCheckUser.Accounts[0].ToString());

                            SPGroupCollection collGroups = user.Groups;
                            if (collGroups.Count > 0)
                            {
                                foreach (SPGroup oGroup in collGroups)
                                {
                                    oGroup.RemoveUser(user);
                                }
                                strError += "User Removed Successfully...!";
                            }


thanks to author @ http://sharepoint2010tutorialnew.blogspot.com/2011/12/deleting-user-within-sharepoint-group.html


Sunday, May 20, 2012

c# , display number in thousands seperator format


 NumberFormatInfo nfi = (NumberFormatInfo)CultureInfo.InvariantCulture.NumberFormat.Clone();
            nfi.NumberGroupSeparator = ",";
            Console.WriteLine(12345.ToString("n", nfi)); // 12,345.00

for my surprise it includes the decimal poiont at last. it made my job easy....:-)

thanks to author @ http://stackoverflow.com/questions/752145/use-a-custom-thousand-separator-in-c-sharp


Tuesday, May 1, 2012

SharePoint : thread was being aborted

I was getting "Thread was being aborted" error while running my workflow. My Workflow required 5-10 mins to finish. but after 2 or 3 mins I started my workflow, it was throwing this error. which i got from my error log.

I could Identify that, the error is coming in different steps (workflow activities) everytime. It means problem is neither with data nor with the code.

then after searching for sometime. I found this article @

http://dirkvandenberghe.com/2010/01/29/sharepoint-timeout-error-thread-was-being-aborted.html

thanks to author.


the actual problem is sharepoint execution time.

The solution to the problem is
<httpRuntime executionTimeout=“200“ maxRequestLength=“51200“/>

try to find the "<httpruntime"  element in your sharepoint's web application's web.config file and include this attribute.  " executionTimeout=“2000“ "


I changed it to "2000". now the problem is solved. (at least for me)

this may help to those who overlooked this check.

Tuesday, April 17, 2012

SharePoint 2010 + ssis adapter + currency field

The currency field in SharePoint list is not updated with the value we get from the source.

After hours of "trail & error" methods, found solution.

Currency field's source data type is "Numeric"

this data type to be changed to "float" using Data Conversion component.

then it worked.




sharePoint + SSIS adapters + The content type text/html; charset=utf-8 of the response message does not match

I am getting the following lengthy error.

[SharePoint List Destination 1 [3738]] Error: System.ServiceModel.ProtocolException: The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (text/xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns:o="urn:schemas-microsoft-com:office:office" lang="en-us" dir="ltr">
<head><meta http-equiv="X-UA-Compatible" content="IE=8" /><meta name="GENERATOR" content="Microsoft SharePoint" /><meta name="progid" content="SharePoint.WebPartPage.Document" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta http-equiv="Expires" content="0" /><title>
   
Error Page

</title><link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/layouts.css?rev=aTcoNUf8p1YiDzYCg3%2FLIw%3D%3D"/>
<link rel="stylesheet" type="text/css" href="/_layouts/1033/styles/Themable/corev4.css?rev=iIikGkMuXBs8CWzKDAyjsQ%3D%3D"/>

    <script type="text/javascript">
    var _fV4UI = true;
    </script>
    <script type="text/javascript">
// <![CDATA[
document.write('<script type="text/javascript" src="/_layouts/1033/init.js?rev=BjQJs0OCQh3Zfydsdw2MYw%3D%3D"></' + 'script>');
document.write(''.

Server stack trace:
   at System.ServiceModel.Channels.HttpChannelUtilities.ValidateRequestReplyResponse(HttpWebRequest request, HttpWebResponse response, HttpChannelFactory factory, WebException responseException, ChannelBinding channelBinding)
   at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
   at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
   at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
   at 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.Samples.SqlServer.SSIS.SharePointUtility.ListsService.ListsSoap.UpdateListItems(UpdateListItemsRequest request)
   at Microsoft.Samples.SqlServer.SSIS.SharePointUtility.ListsService.ListsSoapClient.ListsService_ListsSoap_UpdateListItems(UpdateListItemsRequest request)
   at Microsoft.Samples.SqlServer.SSIS.SharePointUtility.ListsService.ListsSoapClient.UpdateListItems(String listName, XElement updates)
   at Microsoft.Samples.SqlServer.SSIS.SharePointUtility.Adapter.ListsAdapter.ExecuteSharePointUpdateBatch(String listName, String viewId, XElement batchXml, Int16 batchSize)
   at Microsoft.Samples.SqlServer.SSIS.SharePointUtility.ListServiceUtility.UpdateListItems(Uri sharepointUri, NetworkCredential credentials, String listName, String viewName, IEnumerable`1 fieldValueList, Int16 batchSize)
   at Microsoft.Samples.SqlServer.SSIS.SharePointListAdapters.SharePointListDestination.ProcessInput(Int32 inputID, PipelineBuffer buffer)
   at Microsoft.SqlServer.Dts.Pipeline.ManagedComponentHost.HostProcessInput(IDTSManagedComponentWrapper100 wrapper, Int32 inputID, IDTSBuffer100 pDTSBuffer, IntPtr bufferWirePacket)






I got this error while updating data to my sharepoint list. After struggling a lot found the solution.

the problem is,  SharePoint Event Receivers ,  I have some event receivers on this list, while updating those items, it throws the error. ultimately SSIS adapter is throwing error like above.

So i deactivated the feature which contains the event receivers temporarily and executed the SSIS package.

voila  "IT'S WORKING"


This may help those who overlooks the event receivers