User Control in Sandboxed Solutions

Is it possible to create user controls in sand boxed solutions like we do in farm solutions by adding  user control under control templates folder in our code solution??

Application pages, mobile pages, and user controls (.ascx files) cannot be deployed in a sandboxed solution
http://msdn.microsoft.com/en-us/library/office/gg615454%28v=office.14%29.aspx
http://technet.microsoft.com/en-in/library/ee721992%28v=office.14%29.aspx
You can plan to localize these solutions
http://msdn.microsoft.com/en-us/library/office/gg615460%28v=office.14%29.aspx

Similar Messages

  • Sharepoint Taxonomy Control in sandbox solution in sharepoint 2013

    Hi,
    We have requirement  to bind termsets into taxonomy control  using sandbox solution in sharepoint 2013.
    I cannot use webpart,and APP. Below code added in aspx page in module.
    i cannot write any code as this sandbox solution.
    <%@ Register Tagprefix="TaxonomyField" Namespace="Microsoft.SharePoint.Taxonomy" Assembly="Microsoft.SharePoint.Taxonomy, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"
    %>
     <TaxonomyField:TaxonomyWebTaggingControl ID="TWC" runat="server"  SspId="08d413ac-c81d-4232-b1df-c2da46f9b21a" TermSetId="06c93fa1-8a76-4637-9b87-5e612276c199"  AllowFillIn="true" IsMulti="false"
    IsDisplayPickerButton="true"  Language="1033"  IsAddTerms="true" >
        </TaxonomyField:TaxonomyWebTaggingControl>
    This is able to render the control, where as termsets are not being  displayed.
    Please help on this.
    -Navya

    I don't think hard coding SSPID and TermsetID is a good practice. Try to get the values through code and using unique names.
    <Taxonomy:TaxonomyWebTaggingControl ID="TWC" IsDisplayPickerButton="true"
    AllowFillIn="true" runat="server"
    ShowTaxonomy(TWC, TaxonomyGroup, TermSetName);
    public static void ShowTaxonomy(TaxonomyWebTaggingControl control, string taxonomyGroup, string termsetName)
    SPContext context = SPContext.Current;
    SPSite site = context.Site;
    TaxonomySession tsession = new TaxonomySession(site);
    TermStore ttermStore = tsession.TermStores["TermStore"];
    Group tgroup = ttermStore.Groups[taxonomyGroup];
    TermSet productsTermSet = tgroup.TermSets[termsetName];
    control.SspId.Add(ttermStore.Id);
    control.TermSetId.Add(productsTermSet.Id);
    control.IsAddTerms = false;
    control.AllowFillIn = false;
    control.IsMulti = true;
    control.IsIncludeUnavailable = false;
    control.Language = 0;
    if(termsetName==Constants.UserKeywordsTermSet)
    control.AllowFillIn = true;
    control.IsAddTerms = true;
    Bala

  • How to update a People and group field using a sandbox solution

    Hi,
    I am creating a sandbox solution for office 365 and creating a custom form using visual web part, which will allow users to enter data in a custom list.
    And that list also have a user field. I am able to get SharePoint user field on the form (using javascript) which is searching for the user and get a value (working fine).
    Issue: But I am not able to save the user value. Because to save user value I require web, UserID and login name, to construct SPFieldUserValue object or string in "111;#TestUser" format. Moreover that user should be present in
    SiteUserInfoList. 
    I tried web.EnsureUser() but did not work under sanbox solution.
    Can you please provide any pointer or workaround to the problem? I may be missing something here.
    Thanks,
    Himanshu

    Hi,
    According to your description, my understanding is that you want to update the people and group field in Sandbox solution.
    In the sandbox solution, you can still use the web.EnsureUser() function to get the user information, see the thread below:
    EnsureUser in sandboxed solution
    In additional, there is a demo with your similiar requirement for your reference:
    Using the People Picker Control in Sandbox Solutions / Office 365
    Thanks
    Best Regards,
    Jerry Guo
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • Open popup window and redirect user to home page in sandboxed solution

    i've created a sandboxed solution visual webpart and it has submit button so when user fills the information in the text boxes availble in webpart and clicks submit button so I want to open popup button containg success message and ok button so when user
    clicks ok button in popup window i want user to be redirected to the home page of the site.
    i tried to open popup and showed success message by below code
     string gotohomepage = "http://sp2013:1111/Pages/home.aspx";
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "message", "alert('Your Record has been submitted successfully,you will be redirected to home Page shortly');location.href =
    '" + gotohomepage + "';", true);
    but it's not opening popup window can anyone help how do i open popup window and redirect user to home page in sandboxed solution

    Page class and script manager are not supported in sandbox solution
    You can create model popup to achieve this
    below are the reference links
    http://blogs.msdn.com/b/chaks/archive/2011/09/14/modal-dialog-box-in-sharepoint-sandbox.aspx
    http://social.msdn.microsoft.com/Forums/en-US/9427db4d-60f2-4b2a-8db6-b50d01ac4f23/how-to-create-modal-popup-using-sandboxed-solution

  • How can I send an email from Sharepoint Online using sandbox solution?

    How can I send an email from Sharepoint Online using sandbox solution?
    If possible I do not want to use workflow.
    Is It possible to do it without using workflow?

    hello Steven Andrews,
    when any user sends a message using contact us page in SharePoint online.
    1. We are inserting item in Contact Us List . - This is working fine
    for anonymous users also. We have used Office365 anonymous codeplex wsp and it is working fine. Anonymous user is able to insert new record in the Contact Us List.
    2. Once, new record is inserted in Contact Us list, we want to fire email notifying thanks to the user on his email id as well as to our company x person for notification of new inquiry. 
    We tried using Workflow having impersonation step for  anonymous user but it is not working for Anonymous users. Workflow is able to sent the email if someone logged into system but not working for Anonymous user although workflow is getting started
    but not able to send email although used Imperonsation step.
    We are stuck into implementing second step.

  • How to show the text in a textBlock in my user control?

    in my UC i have a textBlock . the text that i put through the xaml or the text that i put through the C# doesn't show:
    <local1:Cell x:Class="UserControls.HintCell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local1="clr-namespace:UserControls"
    mc:Ignorable="d" d:DesignHeight="130" d:DesignWidth="130" Loaded="UserControl_Loaded" >
    <Grid x:Name="hintGrid" MouseLeave="hintGrid_MouseLeave">
    <Grid x:Name="topTriangle" x:FieldModifier="public">
    <Polygon Name="triangle_top" Points="0,0 130,0, 130,130" Stroke="Black" Fill="Red" MouseEnter="triangle_MouseEnter" MouseLeave="triangle_MouseLeave" />
    <TextBlock Name="text_top" Margin="82,20,20,76" FontSize="25" Text="55" Foreground="Black" x:FieldModifier="public"/>
    </Grid>
    <Grid x:Name="bottomTriangle" x:FieldModifier="public">
    <Polygon Name="triangle_bottom" Points="0,0 130,130, 0,130" Stroke="Black" Fill="Red" MouseEnter="triangle_MouseEnter" MouseLeave="triangle_MouseLeave"/>
    <TextBlock Name="text_bottom" Margin="15,80,77,16" FontSize="25" Text="88" x:FieldModifier="public" />
    </Grid>
    </Grid>
    </local1:Cell>
    and the designer:
    but, when debugging the text doesn't show:
    i was told maybe to define the user control or the  text as a dependency property, i don't know how to do it and maybe someone has a better solution?
    thanks.

    thanks. but i didn't really understand, maybe you can give an example with my parameters?
    The text dependency property is called LabelFor.
    It's this bit.
    public string LabelFor
    get { return (string)GetValue(LabelForProperty); }
    set { SetValue(LabelForProperty, value); }
    public static readonly DependencyProperty LabelForProperty = DependencyProperty.RegisterAttached(
    "LabelFor",
    typeof(string),
    typeof(EditRow));
    You would substitute the name of your usercontrol for EditRow when you cut and paste that into it.
    There is a style which defines what EditRow looks like by giving it a template.
    <Style TargetType="{x:Type local:EditRow}">
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type local:EditRow}">
    <Grid>
    <Grid.ColumnDefinitions>
    <ColumnDefinition Width="{Binding RelativeSource={
    RelativeSource FindAncestor,
    AncestorType=local:EditRow},
    Path=LabelWidth, TargetNullValue=2*}"/>
    <ColumnDefinition Width="{Binding RelativeSource={
    RelativeSource FindAncestor,
    AncestorType=local:EditRow},
    Path=PropertyWidth, TargetNullValue=3*}"/>
    </Grid.ColumnDefinitions>
    <TextBlock Text="{Binding RelativeSource={
    RelativeSource FindAncestor,
    AncestorType=local:EditRow},
    Path=LabelFor}"
    HorizontalAlignment="Right"
    Margin="0,4,0,0"/>
    <Border Margin="6,2,6,2" Padding="0,2,0,2" Grid.Column="1" >
    <ContentPresenter HorizontalAlignment="Stretch"/>
    </Border>
    </Grid>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    That uses binding to give the textblock text property the value of LabelFor.
    You could instead put your markup directly in your usercontrol and bind it like that.
    This bit would then pretty much cut and paste in
    <TextBlock Text="{Binding RelativeSource={
    RelativeSource FindAncestor,
    AncestorType=local:EditRow},
    Path=LabelFor}"
    You would need two of course if you have two textblocks.
    ps
    People have suggested dependency property to you because this is how properties on wpf controls work.  
    If you instead chose to use properties then you lose the ability to set value by style, animation, binding etc Your usercontrol will not behave like a wpf control.  This might not really concern you if you're just working on your own on an app.
    It would if you were working in a team though.
    Personally, I would reject code which exposed regular properties from a usercontrol at walk through.
    Hope that helps.
    Recent Technet articles:
    Property List Editing;  
    Dynamic XAML

  • How to Add a User Control to a SharePoint 2013 Visual Web Part ?

    Hi,
    1.I have created SharePoint 2013 Farm Solution through VS 2012.
    2.Added visual Web part
    3.Created a User control (Farm Solution ) and added some Control From tool Box.
    4.Drag and drop user control from solution explorer to visual web part.
    so its  Register tag and with prefix tag user controls automatically added on visual web part source. when i try to build solution it throws Exception:
    Exception :The name 'InitializeControl' does not exist in the current context.
    Please Provide solution after try/or proper workaround.
    Thanks,
    Siddheshwar

    Site name=http://sitename:22222/
    Visual Web part:
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Src="~/_controltemplates/15/SP2013Controls/SPControls.ascx" TagPrefix="uc1" TagName="SPControls" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPWebpart.ascx.cs" Inherits="SP2013Controls.SPWebpart.SPWebpart" %>
    <uc1:SPControls runat="server" id="SPControls" />
    User Control Code:
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="SPControls.ascx.cs" Inherits="SP2013Controls.ControlTemplates.SP2013Controls.SPControls" %>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><asp:Button ID="Button1" runat="server" Text="Button" />
    Deployement Location:{SharePointRoot}\Template\ControlTemplates\SP2013Controls\
    After User controls added on webpart .g.cs file getting blank.
    After 1st Build:
    'InitializeControl' does not exist in the current context
    The file '/_controltemplates/15/SP2013Controls/SPControls.ascx' does not exist.
    after 2nd Build Try:
    'InitializeControl' does not exist in the current context

  • I cannot get a WindowsForms user control hosted in WPF/C# to show() PDF please help

    I have a WPF C# .NET 4.0. solution in VS2010 on Windows 7.   It contains a WPF hosting project and a WindowsFormsControl project where I've created a UserControl that should display an Acrobat CAcroAVDoc object from the Interop.Acrobat SDK com object (latest).
    The WPF Project contains this code to open a file which actually creates a new WindowsFormsUserControl (PDFViewerControl) that in turns opens the file, the UserControl is then added to a WindowsFormHost object in WPF main form.
    private void OpenFile(FileItem file)
    if (file.Extension.ToLower() == ".pdf")
      System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
      WindowsFormsControls.PDFViewerControl viewer = new WindowsFormsControls.PDFViewerControl();
      viewer.Show();
      Boolean result = viewer.OpenFile(file.Path);
      if (!result)
       MessageBox.Show("Error opening document");
      host.Child = viewer;
      this.pdfViewWpf.Children.Add(host);
      viewer.Show();
    The PDFViewerControl OpenFile method contains this code and returns True when opening a PDF document via OpenInWindowEx.
    public Boolean OpenFile(String filename)
    CAcroAVDoc doc = Activator.CreateInstance(Type.GetTypeFromProgID("AcroExch.AVDoc")) as CAcroAVDoc;
    bool res = doc.OpenInWindowEx(filename, this.Handle.ToInt32(), 2, 1, 0, (short)Acrobat.PDViewMode.PDUseBookmarks, (short)Acrobat.AVZoomType.AVZoomFitWidth, 0, 0, 0);
    return res;
    Unfortunately though the PDF cannot be seen in WPF Host object.  If I place a LABEL on the windows forms user control, the label will show in WPF.  It seems the OpenInWindowEx is not loading a PDF object onto the user control.  Perhaps I need a resize method and event?
    I cannot locate any object on the PDFViewerControl user control that resembles a PDF document through debug.
    Any help/pointers much appreciated.
    this.Handle.ToInt32() does have a seemingly valid value (ie window handle).
    this.pdfViewWpf is a XAML <Grid>
    Dominic

    On further testing, I found the above code does actually work, BUT the HOST or the VIEWER or the DOC object disappear after the routine is finished.  I placed a label on the UserControl and noticed a flicker on the crseen draw which I capture on camtasia the result can be viewed here.  http://www.screencast.com/t/Z49gUTb3Xt
    Given the label is still around after the file open routine completes suggests the HOST and VIEWER objects are still exposed, just the DOC object resizes to zero height and width or just plain gone.
    Without the Label, same result.
    Any thoughts on how to retain the display of the CAcroAVDoc object would be much appreciated.

  • Activating Sandbox Solution in SharePoint 2013

    Hi,
    I am having a Single Server (Windows Server 2008 R2 Standard) with Microsoft SharePoint Server 2013 installed on it.
    I have one CRM solution which is sandbox solution and I want to deploy it on site collection. 
    When i am going to SiteSettings > Solutions and upload the solutions and click on Activate button .. nothing is happening and solution is not getting activated. When I tried same with powershell using Install-SPUserSolution, I am getting below error,
    Install-SPUserSolution : Object reference not set to an instance of an object.
    At line:1 char:1
    + Install-SPUserSolution -Identity crmlistcomponent1.wsp -Site
    http://in-mum-appcs ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ~~~
        + CategoryInfo          : InvalidData: (Microsoft.Share...allUserSolution:
       SPCmdletInstallUserSolution) [Install-SPUserSolution], NullReferenceExcept
      ion
        + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletInstallU
       serSolution
    Also, "Microsoft SharePoint Foundation User Code Service" Service is missing on Services On Server page so that I could
    not start it. However I started "SharePoint User Code Host" service in services.msc
    Please help me out, As I have got stuck in this problem from long back.
    Thanks

    From PowerShell, run:
    Install-SPService
    See if the User Code Service is visible on the Manage Services on Server page.
    Trevor Seward
    Follow or contact me at...
    This post is my own opinion and does not necessarily reflect the opinion or view of Microsoft, its employees, or other MVPs.

  • How to create a cluster with a User control (.ctl) programatically using VI scripting?

    Solved!
    Go to Solution.

    It seems that you hit the Post button before you had a chance to use the body of the message to give more detail on what you are trying to do.
    Perhaps you can post whatever VI you have so far and also the user control you are trying to use.

  • Creating Termset and terms in Taxonomy using Sandboxe Solution in Sharepoint 2013

    I created a Sandboxed Solution, Added one Visual web part in that solution with one button control. Added Microsoft.Sharepoint.Taxonomy.dll Reference to the solution. Then in the button click event i wrote the following code:
    SPSite site = SPContext.Current.Site;
                var taxonomySession = new TaxonomySession(site);
                var termStore = taxonomySession.DefaultSiteCollectionTermStore;
                lbl1.Text = termStore.ToString();
                var termStoreGroup = termStore.CreateGroup(txtTermSetGroupVal.Text);
                var termSet = termStoreGroup.CreateTermSet(txtTermSetCatNameVal.Text);
                termSet.CreateTerm("AAA", CultureInfo.CurrentCulture.LCID);
                termSet.CreateTerm("BBB", CultureInfo.CurrentCulture.LCID);
                termStore.CommitAll();
    Then, I deployed this solution in one Publishing site. Added one new page in that site and Inserted this visual webpart in that page. When i click that button, I got the
    following error,
    Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. Correlation ID: 49c1759c-5913-70a8-76e3-b2827260601a.[SPUserCodeSolutionExecutionFailedException:
    Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.]

    Hi,
    The Yammer, OneDrive, Sites , My Sites and so on are buttons in the suite bar, the BROWSE, PAGE, SHARE etc. are the buttons in the ribbon, the two bars are added to the master
    page automatically during the converting process.
    A workaround is that we can hide the ribbon by using such a CSS code:
    Best regards,
    Patrick
    Patrick Liang
    TechNet Community Support

  • How can we increase resource quota of sandbox solution in sharepoint 2013?

    Hi,
    i have created a sandbox solution for sharepoint 2013 but the problem is it shows that your resource usage exceeds your quota.so is there any way we can increase the resource usage quota.
    my application is on sharepoint online 365.
    thanks,
    Gaurav

    Sandbox solutions have been deprecated for SharePoint 2013.  And if you're using this within Office 365, then I'm guessing it means you've navigated directly to the _catalogs/solutions library?  As this resource quota is normally controlled from
    Central Administration, you might be stuck with your curent quota.
    Andy Burns has some interesting observations on Office 365 limitations when it comes to Sandbox solutions
    http://www.novolocus.com/2012/07/17/office-365-technical-observations-from-a-first-project/
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Web Part Error in Sandbox solution

    Hi, I used the following code for "ADD POST IN NEWSFEED USING C#" in sandbox solution 2013.
                        string serverUrl = "http://sanchit:5097/";
                        string accountName = @"tafecorp\spservices";          
                       SocialDataItem userMentionLink = new SocialDataItem
                            ItemType = SocialDataItemType.User,
                            AccountName = accountName
                        SocialPostCreationData postCreationData = new SocialPostCreationData();
                        postCreationData.ContentText = "{0} does great work!";
                        postCreationData.ContentItems = new SocialDataItem[1] { userMentionLink, };
                        try
                            ClientContext clientContext = new ClientContext(serverUrl);
                            SocialFeedManager feedManager = new SocialFeedManager(clientContext);
                            feedManager.CreatePost(null, postCreationData);
                            clientContext.ExecuteQuery();
                            lblReport.Text = "The post was published";
                        catch (Exception ex)
                            lblReport.Text = ex.ToString();
    When i run the code the following error comes.  How to solve this issue. Thanks in advance.
    Web Part Error: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred. Correlation ID: 5f639c9c-7639-50f3-7dce-34ae387d3ed0. 

    Share the details about correlation ID in ULS logs
    http://sharepoint.stackexchange.com/questions/59679/sandbox-unhandled-exception-was-thrown-partial-trust-app-domain
    Well it's taken a few days but I've finally managed to work this one out however it did involve me having to dissect the whole project and reintroduce each piece one at a time.
    A few issues were causing it:-
    1) I had set one of the projects "Include Assembly in Package" property to false.
    2) A static method was making a call to an SPList which turned an empty (null) value. Added a value to that item and the error disappeared.
    3) I'd declared a variable as being of type double and set its default value as 0.
    Now why the system couldn't have told me that's what the problems were rather than throwing this generic error is a different story! It would have saved me many an hour of confusion.
    http://stackoverflow.com/questions/3905388/sharepoint-2010-sandboxed-webpart-error
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/c11ab5df-562e-43b4-b350-5c4d07da8bf3/sandbox-solution-error-unhandled-exception-was-thrown-by-the-sandboxed-code-wrappers-execute?forum=sharepointgeneralprevious
    http://sohilmakwana.wordpress.com/2013/11/29/sandbox-error-unhandled-exception-was-thrown-by-the-sandboxed-code-wrappers-execute-method-in-the-partial-trust-app-domain/
    If this helped you resolve your issue, please mark it Answered

  • Error:System.Web.HttpUnhandledException in Custom Web part for Sandbox solution

    Please Help...
    I have a sandbox solution for Custom Web part which has a 'Visual Web Part(sandbox)'.
    The solution builds, Packages & deploys successfully.
    But when adding this custom web part on a Sharepoint 'Web Part Page' it throws up the below Error:
    Same code when deployed as a Farm Solution works all well.
    Only difference between the two solutions being Farm solution has  'Visual web part'
    and Sandbox solution has 'Visual web part(sandbox)'
    ERROR:
    ======================================================
    [SPUserCodeSolutionExecutionFailedException: Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.]
     Server stack trace:
      at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext
    executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext
    executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeAppDomain.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcessProxyForShim.ExecuteInternal(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext
    executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcessProxy.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext
    executionContext)
      at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
      at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
     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.UserCode.SPUserCodeWorkerProcess.ExecuteDelegate.EndInvoke(IAsyncResult result)
      at Microsoft.SharePoint.UserCode.SPUserCodeWorkerProcess.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, SPUserToken userToken, String currentAffinity, SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodePoolableProcessConnection.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, SPUserToken userToken, String affinity, SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeExecutionHost.Execute(Type userCodeWrapperType, Guid siteCollectionId, SPUserToken userToken, String affinity, SPUserCodeExecutionContext executionContext)
      at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
      at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg, Int32 methodPtr, Boolean fExecuteInContext)
     Exception rethrown at [1]:
      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.Administration.ISPUserCodeExecutionHostProxy.Execute(Type userCodeWrapperType, Guid siteCollectionId, SPUserToken userToken, String affinityBucketName, SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.Execute(Type userCodeWrapperType, SPSite site, SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeWebPartRemoteExecutionHelper.<>c__DisplayClassa.b__9()
      at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode)
      at Microsoft.SharePoint.UserCode.SPUserCodeWebPartRemoteExecutionHelper.ExecuteRequestInSandBox(HttpContext context, SPWeb web, SPWebPartManager manager, SPUserCodeWebPart userCodeWebPart)
    [HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown.]
     Server stack trace:
      at System.Web.UI.Page.HandleError(Exception e)
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
      at System.Web.UI.Page.ProcessRequest()
      at System.Web.UI.Page.ProcessRequest(HttpContext context)
      at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.ExecuteHttpRequest(SPUserCodeWebPartHttpRequestContext webPartExecutionContext, SPUserCodeWebPartHttpResponse httpRequestResponse)
      at Microsoft.SharePoint.UserCode.SPUserCodeWebPartWrapper.Execute(SPUserCodeExecutionContext executionContext)
      at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.ExecuteWrapper(SPUserCodeWrapper wrapper, SPUserCodeExecutionContext executionContext)
      at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Int32 methodPtr, Boolean fExecuteInContext, Object[]& outArgs)
      at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
     Exception rethrown at [0]:
      at System.Runtime.Remoting.Proxies.RealProxy.EndInvokeHelper(Message reqMsg, Boolean bProxyCase)
      at System.Runtime.Remoting.Proxies.RemotingProxy.Invoke(Object NotUsed, MessageData& msgData)
      at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.CodeToExecuteWrapper.EndInvoke(IAsyncResult result)
      at Microsoft.SharePoint.UserCode.SPUserCodeApplicationHostAppDomainRef.Execute(Type userCodeWrapperType, SPUserCodeCachedAssemblyGroup userAssemblyGroup, Guid siteCollectionId, Byte[] binaryUserCodeToken, Byte[] proxyOperationToken, SPUserCodeExecutionContext
    executionContext)
    [InvalidOperationException: Using Menu.DynamicHoverStyle requires Page.Header to be non-null (e.g. <head runat="server" />).]
      at System.Web.UI.WebControls.Menu.EnsureRenderSettings()
      at System.Web.UI.WebControls.Menu.OnPreRender(EventArgs e, Boolean registerScript)
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Control.PreRenderRecursiveInternal()
      at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

    Hi!!
    Sure, Please find .cs and .ascx script below
    ==========.ascx===========================
    <%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
    <%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Import Namespace="Microsoft.SharePoint" %>
    <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="DynamicMenuWP.ascx.cs" Inherits="MenuWebPartProject.DynamicMenuWP.DynamicMenuWP" %>
    <asp:Menu ID="siteStructure" runat="server" Orientation="Horizontal"  StaticPopOutImageTextFormatString="" DynamicHoverStyle-BackColor="#CBE3F0" SkipLinkText=""
                                            StaticSubMenuIndent="10px"
    BackColor="#000000" CssClass="BIMenu" Font-Names="Verdana" Font-Size="1em"  DynamicHorizontalOffset="2" onmenuitemclick="siteStructure_MenuItemClick" Target="_blank">
                                            <StaticSelectedStyle
    BackColor="#507CD1" />
              <StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" CssClass="BIMenuStaticformenu" />
              <DynamicHoverStyle BackColor="#CBE3F0" />
              <DynamicMenuStyle BackColor="#F2F3F4" BorderColor="#A7B4CE" ForeColor="Black" />
              <DynamicSelectedStyle BackColor="#507CD1" />
              <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" CssClass="BIMenuDynamicForMenu" />
            <StaticHoverStyle BackColor="#284E98" ForeColor="White" />
    </asp:Menu>
    ==========.cs===========================
    using System;
    using System.ComponentModel;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace MenuWebPartProject.DynamicMenuWP
        [ToolboxItem(false)]
        public partial class DynamicMenuWP : System.Web.UI.WebControls.WebParts.WebPart
            protected override void OnInit(EventArgs e)
                base.OnInit(e);
                InitializeControl();
            protected void Page_Load(object sender, EventArgs e)
                if (!IsPostBack)
                    ScorecardStructure ss;
                    List<ScorecardStructure> listSS = new List<ScorecardStructure>();
                        using (SPWeb web = SPContext.Current.Web)
                            SPList lists = web.Lists["MenuItems"];
                            if (lists.ItemCount > 0)
                                foreach (SPListItem item in lists.Items)
                                    ss = new ScorecardStructure();
                                    ss.title = Convert.ToString(item["Title"]);
                                    ss.ParentID = Convert.ToInt32(Convert.ToString(item["Parent ID"]));
                                    ss.ParentName = Convert.ToString(item["Parent Name"]);
                                    ss.MenuID = Convert.ToInt32(Convert.ToString(item["Menu ID"]));
                                    ss.menuName = Convert.ToString(item["Menu Name"]);
                                    ss.url = Convert.ToString(item["URL"]);
                                    ss.friendlyName = Convert.ToString(item["Friendly Name"]);
                                    listSS.Add(ss);
                    if (listSS.Count > 0)
                        List<ScorecardStructure> y = listSS.Where(s => s.ParentID == 0).ToList<ScorecardStructure>();
                        foreach (var x in y)
                            MenuItem newMenuItem = new MenuItem(x.menuName.ToString(), x.MenuID.ToString());
                            siteStructure.Items.Add(newMenuItem);
                            AddChildMenuItems(listSS, newMenuItem);
            private void AddChildMenuItems(List<ScorecardStructure> menuData, MenuItem parentMenuItem)
                if (menuData.Count > 0)
                    List<ScorecardStructure> childItems = menuData.Where(s => s.ParentID == Convert.ToInt32(parentMenuItem.Value)).ToList<ScorecardStructure>();
                    foreach (var v in childItems)
                        MenuItem newMenuItem = new MenuItem(v.menuName.ToString(), v.MenuID.ToString());
                        newMenuItem.NavigateUrl = v.url.ToString();
                        parentMenuItem.ChildItems.Add(newMenuItem);
                        // This code is used to recursively add child menu items filtering by ParentID
                        AddChildMenuItems(menuData, newMenuItem);
            protected void siteStructure_MenuItemClick(object sender, MenuEventArgs e)
                string st = e.Item.NavigateUrl;
                if (!(st.Equals(string.Empty)))
                    HttpContext.Current.Response.Redirect(st);
            class ScorecardStructure
                public string title { get; set; }
                public int ParentID { get; set; }
                public string ParentName { get; set; }
                public int MenuID { get; set; }
                public string menuName { get; set; }
                public string url { get; set; }
                public string friendlyName { get; set; }
            public bool IsPostBack { get; set; }

  • Web form User Control

    Hello all,
    I have created a simple web page with 4 cascading dropdowns that pulls its data from a web service and it is functioning nicely. 
    I will probably need this functionality on a few different pages so I thought it might make sense to encapsulate this into a User Control.  From the my research it seems like this might not be an easy undertaking, and a User Control cannot access a
    web service.
    Any suggestions/advice on this topic would be greatly appreciated.
    Warren
    Warren M

    Some are taking the easy way out and pointing you toward ASP.NET only forum, but I believe you can effectively achieve a solution to your problem using only C#, as ASP.NET is just an API for web control control classes defined in C#.
    You should create a base user control class inheriting the user control class, and then define a method in the base user control class to create your objects and populate them.  Encapsulation 101.
    Here is a somewhat abstract example of how you could achieve this.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    namespace WebApplication1
    public class BaseUserControl : System.Web.UI.UserControl
    protected void Page_Load(object sender, EventArgs e)
    protected void PopulateDropdowns()
    // Logic to retrieve data and populate controls
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    namespace WebApplication1
    public partial class MyUserControl : BaseUserControl
    protected void Page_Load(object sender, EventArgs e)
    base.PopulateDropdowns();
    You wouldn't have to put it into a separate method, you could get away with putting it in Page_Load of the BaseUserControl class, but I separated it out for demonstration purposes.
    Best of luck.

Maybe you are looking for

  • Edge Commons Spotlight not working any more on the new version of Edge Animate CC 2014.1

    Hi, i am trying to use the Edge Commons Spotlight but with the new version of Edge Animate cc 2014.1 is not working right. The result is a black transparent background with a little white spot on the center. Please help!!! CompositionReady: yepnope({

  • I18N, Sending from flex to Java server

    Hi I'm doing a flex application for client and Java for server side. i want to send the name of the user to the server. <Code> var loader:URLLoader = new URLLoader(); var vars:URLVariables = new URLVariables(); vars.name = name <-or-> vars.name = esc

  • Are there any scanners that are compatible with OS X Yosemite?

    I just bought the iMac with the 5k screen 27-inch: 3.5GHz with Retina 5K display 3.5GHz quad-core Intel Core i5 Turbo Boost up to 3.9GHz 8GB (two 4GB) memory 1TB Fusion Drive1 AMD Radeon R9 M290X with 2GB video memory I also bought a new scanner (Can

  • Publish SFTP with UAG

    Hello Is it possible and if so, can anyone provide direction for publishing an SFTP server with UAG? I'm essentially looking for direct proxy with no UAG portal authentication. Thank you!

  • Convert text to number

    I imported 3 numbers separated by semicolons into a cell in Numbers.  How do I separate each number into a cell?