Is it possible to make a String in a web part properties editable with a rich text box (to be able to use the Bold, etc.) ?
UPDATE / SOLUTION
The 1st class is the "Custom property" that should appear in the toolbar
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
namespace MyCustomProperty
{
public class RichTextToolbarProperty : Microsoft.SharePoint.WebPartPages.ToolPart
{
InputFormTextBox textBox;
Panel toolPartPanel;
protected override void CreateChildControls()
{
toolPartPanel = new Panel();
toolPartPanel.GroupingText = "Default text here";
textBox = new InputFormTextBox();
textBox.TextMode = TextBoxMode.MultiLine;
textBox.Rows = 10;
textBox.RichText = true;
textBox.RichTextMode = SPRichTextMode.FullHtml;
BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
textBox.Text = wp.DefaultText;
toolPartPanel.Controls.Add(textBox);
Controls.Add(toolPartPanel);
base.CreateChildControls();
}
public override void ApplyChanges()
{
BasePublicationWebPart wp = (BasePublicationWebPart)this.ParentToolPane.SelectedWebPart;
wp.DefaultText = textBox.Text;
}
}
}
The 2nd class is the WebPart :
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace MyWebPart
{
public abstract class BasePublicationWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
public string DefaultText
{
get
{
return _defaultText;
}
set { _defaultText = value; }
}
public override ToolPart[] GetToolParts()
{
ToolPart[] allToolParts = new ToolPart[3];
WebPartToolPart standardToolParts = new WebPartToolPart();
CustomPropertyToolPart customToolParts = new CustomPropertyToolPart();
allToolParts[0] = standardToolParts;
allToolParts[1] = customToolParts;
allToolParts[2] = new MyCustomProperty.RichTextToolbarProperty();
return allToolParts;
}
// ... some usual web part code should go here ... ///
Yes it is, you might want to inspect, how the "Custom Content Editor Web Part" is built: http://www.codeproject.com/KB/sharepoint/Custom_CEWP_4_SharePoint.aspx
Related
I have .net core web api application. I need to send out the email using razor view. I cannot get razor view as string to send out the email.
I get the exception at Engine.Razor.RunCompile(razorView, "templateKey" + DateTime.Now.Ticks, null, model);
Below is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using MyProject.Api.Models;
using RazorEngine;
using RazorEngine.Templating;
namespace MyProject.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AppointmentBookingController : ControllerBase
{
private readonly IHostingEnvironment _hostingEnvironment;
public AppointmentBookingController(IHostingEnvironment hostingEnvironment)
{
_hostingEnvironment = hostingEnvironment;
}
[HttpGet]
[Route("GetViewAsString")]
public string GetViewAsString()
{
string webRootPath = _hostingEnvironment.WebRootPath;
string contentRootPath = _hostingEnvironment.ContentRootPath;
BaseHttpRequestModel model = new BaseHttpRequestModel
{
LanguageID = "ABC"
};
string razorView = System.IO.File.ReadAllText(contentRootPath + #"\Views\EmailTemplates\Test.cshtml");
Engine.Razor.RunCompile(razorView, "templateKey" + DateTime.Now.Ticks, null, model);
return razorView;
}
}
}
You need to supply the model type instead of passing null when using a strongly typed model. You pass null in when using anonymous or dynamic types. Also return the output of RunCompile:
...
var result = Engine.Razor.RunCompile(razorView, "templateKey" + DateTime.Now.Ticks, model.GetType(), model);
return result;
After using Android layout this.SetContentView(Resource.Layout.Main), and LoadApplication(new App()), I could not see Xamarin.Forms MainPage.xaml. I tried to remove the Linear Layout, but it just removing items inside them, not the form itself. It seems like SetContentView blocking the Xamarin.Forms. So,
Here is MainActivity.cs:
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Text.Method;
using Android.Widget;
using Auth0.OidcClient;
using IdentityModel.OidcClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace IndoFellowship.Droid {
// Define App icon and name
[Activity(
Label = "Indo App",
MainLauncher = true,
Icon = "#drawable/icon",
LaunchMode = LaunchMode.SingleTask)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
// Showing layout that I set
SetContentView(Resource.Layout.Main);
// Do login
// Some codes
// Done processing on Android, I need to load Xamarin.Forms
LinearLayout mainLayout = (LinearLayout)FindViewById(Resource.Id.mainLayoutID);
mainLayout.RemoveAllViews();
// Load App
LoadApplication(new App());
}
}
}
Main.axml on Resources/values/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayoutID"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
// Some layout here..
</LinearLayout>
and my App.xaml.cs (Xamarin)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace IndoFellowship {
public partial class App : Application {
public static string AppName { get; set; }
public App() {
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
protected override void OnStart() {
// Handle when your app starts
}
protected override void OnSleep() {
// Handle when your app sleeps
}
protected override void OnResume() {
// Handle when your app resumes
}
}
}
MainPage.xaml.cs (Xamarin)
using Auth0.OidcClient;
using IdentityModel.OidcClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Auth;
using Xamarin.Forms;
namespace IndoFellowship
{
public partial class MainPage : ContentPage {
public MainPage()
{
InitializeComponent();
var browser = new WebView();
browser.Source = "http://xamarin.com";
Content = browser;
}
}
}
Over here I should seeing xamarin.com webView, but my Android just went blank. It seems like Xamarin.Forms not showing at all and I am still on Xamarin.Android. If I took SetContentView, I can see the forms rendered perfectly, but I could not process what I need to do on Android.
What I need to do to properly load Xamarin Forms from MainActivity?
Why layout not removed?
Thank you.
I found my solution by using StartActivity instead of LoadApplication.
By creating a second activity:
XamarinForms.cs this activity load the app()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
namespace IndoFellowship.Droid {
[Activity(Label = "XamarinForm")]
public class XamarinForm : Xamarin.Forms.Platform.Android.FormsApplicationActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
}
}
}
MainActivity.cs instead of LoadApplication here, I am calling the second activity instead
using Android.App;
using Android.Content;
using Android.Content.PM;
using Android.OS;
using Android.Text.Method;
using Android.Widget;
using Auth0.OidcClient;
using IdentityModel.OidcClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xamarin.Forms;
namespace IndoFellowship.Droid {
// Define App icon and name
[Activity(
Label = "Indo App",
MainLauncher = true,
Icon = "#drawable/icon",
LaunchMode = LaunchMode.SingleTask)
]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
// Showing layout that I set
SetContentView(Resource.Layout.Main);
// Do login
// Some codes
// Done processing on Android, I need to load Xamarin.Forms
LinearLayout mainLayout = (LinearLayout)FindViewById(Resource.Id.mainLayoutID);
mainLayout.RemoveAllViews();
// Load App
StartActivity(typeof(XamarinForms));
}
}
}
May be this is not a best design since now I have two activities. Please let me know if you know better way to accomplish this. Thank you.
I am trying to add an option under Actions in Acumatica on the Checks & Payment screen AP302000. See below what I am trying to achieve:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Runtime.Serialization;
using PX.Common;
using PX.Data;
using PX.Objects.CM;
using PX.Objects.CA;
using PX.Objects.CS;
using PX.Objects.GL;
using PX.Objects.CR;
using PX.Objects;
using PX.Objects.AP;
namespace PX.Objects.AP
{
public class APPaymentEntry_Extension:PXGraphExtension<APPaymentEntry>
{
#region Event Handlers
public PXAction<APPayment> ShowURL;
[PXUIField(DisplayName = "Print Remittance")]
[PXButton]
protected virtual void showURL()
{
APPayment doc = Document.Current;
if (doc.RefNbr != null) {
throw new PXReportRequiredException(doc.RefNbr, "AP991000", null);
}
}
#endregion
}
}
This is however telling me that there is no definition and no extension method for 'APPayment'. Can someone please walk me through how to achieve what I am trying to do?
Note that the report has only 1 parameter (RefNbr)
Thanks,
G
To Add a new Action in existing Actions Menu, you should override the Initialize() method and use AddMenuAction.
public class APPaymentEntry_Extension : PXGraphExtension<APPaymentEntry>
{
public override void Initialize()
{
Base.action.AddMenuAction(ShowURL);
}
public PXAction<APPayment> ShowURL;
[PXUIField(DisplayName = "Print Remittance")]
[PXButton]
protected virtual void showURL()
{
APPayment doc = Base.Document.Current;
if (doc.RefNbr != null)
{
throw new PXReportRequiredException(doc, "AP991000", null);
}
}
}
Document.Current should be accessed as Base.Document.Current in Extensions. You need to pass the DAC as first parameter in PXReportRequiredException if DAC has the appropriate parameter value. Alternatively, you can build parameters and pass it to PXReportRedirectException.
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters["ParameterName1"] = <Parameter Value>;
...
throw new PXReportRequiredException(parameters, <reportID>, "Report")
The code provided in the book Pro ASP.NET MVC 5 from Apress in chapter 16 (Routing Incoming URLs) The example is about legacy urls. Next i will put the code samples for the custom route, routeconfig, controller and view.
LegacyRoute.cs
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace UrlsAndRoutes.Infrastructure
{
public class LegacyRoute : RouteBase
{
private string[] urls;
public LegacyRoute(params string[] targetUrls)
{
urls = targetUrls;
}
public override RouteData GetRouteData(HttpContextBase httpContext)
{
RouteData result = null;
string requestedURL = httpContext.Request.AppRelativeCurrentExecutionFilePath;
if (urls.Contains(requestedURL, StringComparer.OrdinalIgnoreCase))
{
result = new RouteData(this, new MvcRouteHandler());
result.Values.Add("controller", "Legacy");
result.Values.Add("action", "GetLegacyURL");
result.Values.Add("legacyURL", requestedURL);
}
return result;
}
public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
{
VirtualPathData result = null;
if (values.ContainsKey("legacyURL") && urls.Contains((string)values["legacyURL"], StringComparer.OrdinalIgnoreCase))
{
result = new VirtualPathData(this, new UrlHelper(requestContext).Content((string)values["legacyURL"]).Substring(1));
}
return result;
}
}
}
RouteConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Mvc.Routing.Constraints;
using UrlsAndRoutes.Infrastructure;
namespace UrlsAndRoutes
{
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapMvcAttributeRoutes();
//routes.MapRoute("NewRoute", "App/Do{action}", new { controller = "Home", id = UrlParameter.Optional });
//routes.Add(new Route("SayHello", new CustomRouteHandler()));
routes.Add(new LegacyRoute("~/articles/Windows_3.1_Overview.html", "~/old/.NET_1.0_Class_Library"));
routes.MapRoute("MyRoute", "{controller}/{action}", new { controller = "Home", action = "Index" });
routes.MapRoute("MyOtherRoute", "App/{action}", new { controller = "Home" });
}
}
}
LegacyController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace UrlsAndRoutes.Controllers
{
public class LegacyController : Controller
{
public ActionResult GetLegacyURL(string legacyURL)
{
return View((object)legacyURL);
}
}
}
GetLegacyURL.cshtml
#model string
#{
ViewBag.Title = "GetLegacyURL";
Layout = null;
}
<h2>GetLegacyURL</h2>
The URL requested was: #Model
I can't figure how to put it work. I always get 404 error (http://my.machine/articles/Windows_3.1_Overview.html). The method in the GetRouteData in LegacyRoute.cs is never called. If I remove the . from the URL the code works fine. Can anyone give some advice or help?
It is strange that no one are complaining that the code doesn't work.
Page 445 provides the solution. You need to edit IIS Express settings.
Right click on the IIS Express icon on the taskbar while the application is running -> Show all applications -> Click on the site you want to configure -> Click on the configuration file
Search for System.Web.Routing.UrlRoutingModule
Remove the preCondition attribute value so the line becomes <add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
Restart the application and you are ready.
routes.MapMvcAttributeRoutes();
routes.Add(new LegacyRoute("~/articles/Windows_3.1_Overview.html/",
"~/old/.NET_1.0_Class_Library/"));
routes.MapRoute("MyRoute", "{controller}/{action}", new { controller = "Home" ,action="index" });
routes.MapRoute("MyOtherRoute", "App/{action}", new { controller = "Home" });
Try with above code , this should be worked.
Malinda Sanjaka
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace abc
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
EmoticonRender ab = new EmoticonRender();
private void button1_Click(object sender, EventArgs e)
{
string textie = ab.Parse(textBox1.Text);
richTextBox1.Text += textie+"\n";
}
}
public class EmoticonRender
{
private List<KeyValuePair<string, string>> _dictionary = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>(":-)", "a.png"),
new KeyValuePair<string, string>(";-(", "a.png"),
};
public string Parse(string text)
{
foreach(KeyValuePair<string, string> kvp in _dictionary)
{
text = text.Replace(kvp.Key, #"C:\Users\Buddiez\Documents\Visual Studio 2010\Projects\abc\abc\a.png");
}
return text;
}
}
}
im using these line of codes to insert smilyes into richtextbox but instead of showing smileye it is showing the path of the png imgae ie. C:\Users\Buddiez\Documents\Visual Studio 2010\Projects\abc\abc\a.png
Copy all the images which you have and navigate to >> visual studio select Project>>Properties.There select Resources and paste all copied images on the right side pane.
Hashtable emotions;
void CreateEmotions()
{
emotions= new Hashtable(6);
emotions.Add(":-)", Project.Properties.Resources.regular_smile);
emotions.Add(":)", Project.Properties.Resources.regular_smile);
}
void AddEmotions()
{
foreach (string emote in emotions.Keys)
{
while(richTextBox1.Text.Contains(emote))
{
int ind = richTextBox1.Text.IndexOf(emote);
richTextBox1.Select(ind, emote.Length);
Clipboard.SetImage((Image)emotions[emote]);
richTextBox1.Paste();
}
}
}
A good (and relatively new) solution could be using the open-source EmojiBox project.
There's not much code there so it's quite easy to follow, just note that in order to insert an emoji into the custom RichTextBox there, the text you type has to follow the template of :emoji_name:
Of course, if you don't want to use the whole list of unicode emojis, you could also replace the image files or their names/descriptions within the json file.