How to get file stream from the sharepoint file url in dynamic crm plugin? - sharepoint

I have requirement to get file stream of share point file, for the that I have share point file URL.
https://mysite.sharepoint.com/sites/documents/contact/test/Beat01_07262017.pdf
I’m trying to connect to SharePoint Online (using CSOM) from within a plugin in CRM Online . For that to work, I merged the SharePoint Client and Client.Runtime DLL’s with ilmerge.exe into my plugin DLL. But as soon as the following code:
ClientContext clientContext = new ClientContext(server);
clientContext.Credentials = new SharePointOnlineCredentials(UserId, Password); // This line throws an below exception:
Request for the permission of type
‘System.Security.Permissions.RegistryPermission, mscorlib,
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′
failed.
Is there any way to make it working?
I have checked with SharePoint Integration from CRM Online Workflow/Plugin but not able to get it working
and getting error as below
Exception: Exception has been thrown by the target of an invocation.
Stack Trace at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[]
arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,
Object[] parameters, Object[] arguments)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.DynamicInvoke(Delegate project,
Object[] args)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateExpressionToConditionValue(Expression
exp, ParameterExpression[] parameters)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereCondition(BinaryExpression
be, FilterExpressionWrapper parentFilter, Func 2 getFilter, Func 2
getLinkLookup, Boolean negate)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(String
parameterName, BinaryExpression be, FilterExpressionWrapper
parentFilter, Func 2 getFilter, List 1 linkLookups, Boolean
negate)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhereBoolean(String
parameterName, Expression exp, FilterExpressionWrapper parentFilter,
Func 2 getFilter, List 1 linkLookups, BinaryExpression parent, Boolean
negate)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.TranslateWhere(QueryExpression
qe, String parameterName, Expression exp, List 1 linkLookups)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.GetQueryExpression(Expression
expression, Boolean& throwIfSequenceIsEmpty, Boolean&
throwIfSequenceNotSingle, Projection& projection,
NavigationSource& source, List 1& linkLookups)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.Execute[TElement](Expression
expression)
at Microsoft.Xrm.Sdk.Linq.QueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression
expression)
at System.Linq.Queryable.FirstOrDefault[TSource](IQueryable 1
source)
at CRMPluginProject1._365Immo.Laurus.SharePoint.DocumentLocationHelper.GetDocumentLocationPath(SharePointDocumentLocation
parentLocation)
at CRMPluginProject1._365Immo.Laurus.SharePoint.DocumentLocationHelper.CreateDocumentLocation(Entity
site, String documentLibraryName, EntityReference
regardingRecord)
at CRMPluginProject1._365Immo.Laurus.Plugins.GetSharePointFile.Execute(IServiceProvider
serviceProvider)
Inner Exception :
The demand failed due to the code access security information captured during the creation of an anonymously hosted
dynamic method. In order for this operation to succeed, ensure that
the demand would have succeeded at the time the method was created.
See http://go.microsoft.com/fwlink/?LinkId=288746 for more
information.
Stack Trace : at lambda_method(Closure )

The SharePoint client library apparently needs access to the Windows registry. This is not allowed in sandboxed CRM plugins.
In sandboxed plugins code is only allowed to access resources on the web using the http or https protocol. (IP addresses are not allowed either.)

Related

Can not select value in a combo box in coded UI test using coded UI test builder

I am working on a WPF application which has several custom controls. I am using coded UI test builder to create a script for my application testing. When I run the test, it gives me an exception and the exception occurs at the line shown below.
uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;
I have tried using mouse clicks and changing the coordinates but that does not work as well.
The code for the function is
region Variable Declarations
WpfCustom uIItemCustom = this.UIIntelliClientWindow.UIItemCustom;
WpfComboBox uIRadComboBoxComboBox = this.UIIntelliClientWindow.UIEventInfoRegionCustom1.UIPleasewaitProgressBar.UIRadComboBoxComboBox;
#endregion
// Click custom control
Mouse.Click(uIItemCustom, new Point(448, 307));
// Select 'Wedding' in 'RadComboBox' combo box
uIRadComboBoxComboBox.SelectedItem = this.SelectingWeddingParams.UIRadComboBoxComboBoxSelectedItem;
The exception is pasted below.
Result StackTrace:
at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.FindAllDescendants(String bstrQueryId, Object& pvarResKeys, Int32 cResKeys, Int32 nMaxDepth)
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindAllScreenElement(String queryId, Int32 depth, Boolean singleQueryId, Boolean throwException, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.FindScreenElement(String queryId, Int32 depth, Boolean resetSkipStep)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
--- End of inner exception stack trace ---
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapControlNotFoundException(COMException ex, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, IPlaybackContext context)
at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(Exception exception, String queryId)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindFirstDescendant(String queryId, Int32 maxDepth, Int32& timeLeft)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.GetElement(Boolean useCache, ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.SearchHelper.Search(ISearchArgument searchArg)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindInternal()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.FindControlIfNecessary()
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetPropertyPrivate(String propertyName, Object value)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.<>c__DisplayClass180_0.b__0()
at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.SetProperty(String propertyName, Object value)
at Microsoft.VisualStudio.TestTools.UITesting.WpfControls.WpfComboBox.set_SelectedItem(String value)
at AddingEventUsingDataDrivenTesting.UIMap.SelectingWedding() in C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\UIMap.Designer.cs:line 166
at AddingEventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1() in C:\Users\Dev2\source\repos\AddingEventUsingDataDrivenTesting\AddingEventUsingDataDrivenTesting\CodedUITest1.cs:line 30
Result Message:
Test method AddingEventUsingDataDrivenTesting.CodedUITest1.CodedUITestMethod1 threw exception:
Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details:
TechnologyName: 'UIA'
FrameworkId: 'Wpf'
ControlType: 'ComboBox'
HelpText: 'RadComboBox'
Instance: '2'
Search may have failed at '' TabList as it may have virtualized children. If the control being searched is descendant of '' TabList then including it as the parent container may solve the problem. ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
I face the same issue when I try to automate the wpf controls with coded UI.
The best solution I would like to suggest is to use Appium WinAppDriver(If it is possible for you) as it supports the wpf controls as mentioned my Microsoft team.
here is the guide to : How to use WinAppDriver
CodedUI will be deprecated after Visual studio 2019(mentioned by one of the member of microsoft team in a video) although support will be there.
And for the work around I would suggest you to use the Keyboard.Sendkeys() to set the combobox.
for exmaple :-
UITestControl combobox = new UITestControl();
//add properties of combobox
WinEdit textboxOfCombobox = new WinEdit(comboBox);
textboxOfCombobox.SendKeys("value to enter");
// Add code to verify if the combobox has the correct value selected.
This workaround I use personally and it works for me.
I hope this helps.

Orchard CMS Duplicate Content Error

We have a web site built with Orchard CMS v1.8. We have had a couple of instances where the person that manages content has not been able to save changes to a Page. They receive the following error.
An unhandled exception has occurred and the request was terminated. Please refresh the page. If the error persists, go back
Sequence contains more than one matching element
System.InvalidOperationException: Sequence contains more than one matching element at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source, Func2 predicate) at Orchard.ContentManagement.DefaultContentManager.BuildNewVersion(ContentItem existingContentItem) in c:\Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 450 at Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options, QueryHints hints) in c:\Orchard\src\Orchard\ContentManagement\DefaultContentManager.cs:line 234 at Orchard.Core.Contents.Controllers.AdminController.EditPOST(Int32 id, String returnUrl, Action1 conditionallyPublish) in c:\Orchard\src\Orchard.Web\Core\Contents\Controllers\AdminController.cs:line 308 at lambda_method(Closure , ControllerBase , Object[] ) at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary2 parameters) at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary2 parameters) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult2.CallEndDelegate(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.b__3f() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.b__41() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.b__41() at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass48.b__41()
What can I do to elimiate the extra record(s) returned in the SingleOrDefault() call? I don't know the database structure behind Orchard enough to find the "content records" but if I was able to find them I could delete the extra record(s).
Thanks!
The cause for this error that you have more than one version of the same content item with value Latest = 1 (orchard use this value to determine the latest version for content item), to solve it you can run the following query to find the duplicate versions:
SELECT *
FROM Orchard_Framework_ContentItemVersionRecord
WHERE ContentItemRecord_id = #Id
then be sure that there is only one record with value Latest = 1, published = 1, and Number is in sequence without duplicates.
FYI, in query use value Id for content item which has the error.

Custom Field Search via GetList

We have created three custom field for the StockItem screen (see attached image).
Oz Custom Fields
We would like to search via the Web Services Endpoint (WSE) 5.30.001 using one of these CustomFields, to achieve this we created a new OzStockItem element in our WSE definition Oz WSE Definition and are attempting to use this via the following code.
var itemList = c.GetList(new OzStockItem { OzMinCount = new IntSearch { Condition = IntCondition.IsGreaterThan, Value = 0 } }, false).Cast<OzStockItem>();
However instead of getting back a list of the items that match the filter it is failing with the following error.
An unhandled exception of type 'System.ServiceModel.FaultException' occurred in mscorlib.dll
Additional information:
System.Web.Services.Protocols.SoapException: Server was unable to process request.
---> System.InvalidCastException: Specified cast is not valid.
at PX.Api.ContractBased.ExportTableToEntitiesMapper.<MapCustomFields>d__28.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at PX.Api.ContractBased.ExportTableToEntitiesMapper.<MapEntitiesInner>d__26.MoveNext()
at PX.Api.ContractBased.ExportTableToEntitiesMapper.<MapEntities>d__25.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at PX.Api.ContractBased.EntityService.GetList(EntityGateBase gate, String version, String name, EntityImpl entity, Boolean returnFullEntities, Boolean ignoreValueFields, PXGraph graph)
at PX.Api.ContractBased.Soap.EntityGate.GetList(Entity entity, Boolean returnFullEntities)
Please could someone advise what we are missing here?

Power Query error - Unable to get the NumberFormat property of the Range class

I can't find any search results on this error:
Unable to **get** the NumberFormat property of the Range class
There are tons of search results about this Excel error:
Unable to **set** the NumberFormat property of the Range class
Here is error screenshot.
I am getting this error when refreshing Power Query using VBA, but not when refreshing query directly:
ThisWorkbook.Worksheets("mySheet").Range("myQueryRange").ListObject.QueryTable.Refresh
This is the error message:
Error Message:
Unable to get the NumberFormat property of the Range class
Stack Trace:
Microsoft.Mashup.Client.ClientShared.Com.ComWrapperException: Unable to get the NumberFormat property of the Range class ---> System.Runtime.InteropServices.COMException: Unable to get the NumberFormat property of the Range class
--- End of inner exception stack trace ---
at Microsoft.Mashup.Client.ClientShared.Com.ComWrapper.InvokeMember(String memberName, BindingFlags bindingFlags, Object[] args)
at Microsoft.Mashup.Client.Excel.Renderers.TableRenderer.ApplyColumnFormats(IListObject listObject, FillColumnType[] columnTypes, FillColumnType[] previousColumnTypes)
at Microsoft.Mashup.Client.Excel.Renderers.TableRenderer.ApplyFormatting(IApplication application, IListObject listObject, FillColumnType[] columnTypes, IEnumerable`1 recordFieldTypes, FillColumnType[] previousColumnTypes)
at Microsoft.Mashup.Client.Excel.Shim.AddInFillServices.<>c__DisplayClass19.<PerformPostRefreshFixups>b__17()
at Microsoft.Mashup.Client.Excel.BufferedPainter.<>c__DisplayClass1.<TryPaint>b__0()
at Microsoft.Mashup.Client.Excel.BufferedPainter.TryPaint(Func`1 paintAction)
at Microsoft.Mashup.Client.Excel.BufferedPainter.TryPaint(IApplication application, Func`1 paintAction)
at Microsoft.Mashup.Client.Excel.FillManager.RefreshFillSession.CompleteRefresh(IWorkbook workbook, Boolean onTimer)
at Microsoft.Mashup.Client.Excel.FillManager.RefreshFillSession.UpdateRefreshStatus(IWorkbook workbook, Boolean onTimer)
at Microsoft.Mashup.Client.Excel.FillManager.RefreshFillSession.ResumeFill(Boolean onTimer)
at Microsoft.Mashup.Client.Excel.FillManager.UpdateQueries()
at Microsoft.Mashup.Client.Excel.FillManager.<OnFillUpdateTimerTick>b__5()
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
Invocation Stack Trace:
at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
at Microsoft.Mashup.Client.ClientShared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace)
at Microsoft.Mashup.Client.ClientShared.UnexpectedExceptionHandler.<>c__DisplayClass1.<HandleException>b__0()
at Microsoft.Mashup.Client.ClientShared.UnexpectedExceptionHandler.HandleException(Exception e)
at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Any ideas on what is happening?
My environment:
Windows 7
Excel 2010 64 bit
Power Query Version: 2.29.4217.1861
If you can click that send-a-frown button, can you send the error details to our excellent troubleshooting team? Maybe we've seen it before, but I don't see any issue in our bug database filed for this.
(To save you some time, the first thing we'll probably recommend is to try updating Power Query add-in. The latest version is at 2.32.)

PowerShell and SharePoint 2007: Cannot find an overload for "Add" and the argument count: "2"

I am trying to write a PowerShell script to enable a feature on all subwebs of a given site collection and everything was going swimmingly until I tried to get the actual feature to be enabled. I am successful in using the SharePoint API everywhere, but when i get to this:
$activatedFeature = $web.Features.Add($Feature.Id, $true)
I am getting a ridiculous exception that I cant seem to figure out.
System.Management.Automation.MethodException: Cannot find an overload for "Add" and the argument count: "2".
at System.Management.Automation.Adapter.FindBestMethod(String methodName, MethodInformation[] methods, Object[] arguments, Boolean& expandParamsOnBest)
at System.Management.Automation.DotNetAdapter.MethodInvokeDotNet(String methodName, Object target, MethodInformation[] methodInformation, Object[] arguments)
at System.Management.Automation.Adapter.BaseMethodInvoke(PSMethod method, Object[] arguments)
at System.Management.Automation.ParserOps.CallMethod(Token token, Object target, String methodName, Object[] paramArray, Boolean callStatic, Object valueToSet)
at System.Management.Automation.MethodCallNode.InvokeMethod(Object target, Object[] arguments, Object value)
at System.Management.Automation.MethodCallNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
at System.Management.Automation.AssignmentStatementNode.Execute(Array input, Pipe outputPipe, ExecutionContext context)
at System.Management.Automation.StatementListNode.ExecuteStatement(ParseTreeNode statement, Array input, Pipe outputPipe, ArrayList& resultList, ExecutionContext context)
I cant say that this exception makes much sense to me, nor can I find anything helpful from resources here or searching on key terms.
Has anyone experienced something like this before? If so, how do i correct it.
I had written a function to return the SPFeatureDefinition of the feature being activated and apparently it was returning an array of two items. The second item in the array was the SPFeatureDefinition and I was not aware of this. So, after calling that function i did this:
$Feature = $Feature[1]
After this, everything worked fine.

Resources