How to open appointment item from ribbon button click - vsto

I need to open Outlook appointment item from ribbon button click.
var item = control.Context as Inspector;
AppointmentItem appointmentItem = item.CurrentItem as AppointmentItem;
if (appointmentItem != null)
{
if (appointmentItem.EntryID == null)
{
appointmentItem.Subject = "New Appointment";
appointmentItem.Body = "Welcome to new appointment";
}
}
It should open the appointment window but it is giving null reference error as in this line of code "var item = control.Context as Inspector;" the item is null.

Here's an example of the XML code.
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns">
<group id="MyGroup"
label="My Group">
<button
id="btnNewAppointment"
label="New Appointment"
onAction="NewAppointment"
imageMso="NewAppointment"
size="large"
screentip="New Appointment"
supertip="Create a new appointment"
/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
And here's an example of the C# code.
public void NewAppointment(Office.IRibbonControl control)
{
try
{
Microsoft.Office.Interop.Outlook.Application app = Globals.ThisAddIn.Application;
Microsoft.Office.Interop.Outlook.AppointmentItem newAppointment = (Microsoft.Office.Interop.Outlook.AppointmentItem)
app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
newAppointment.Start = DateTime.Now.AddHours(2);
newAppointment.End = DateTime.Now.AddHours(3);
newAppointment.Location = "ConferenceRoom #2345";
newAppointment.Body = "We will discuss progress on the group project.";
newAppointment.AllDayEvent = false;
newAppointment.Subject = "Group Project";
newAppointment.Recipients.Add("Roger Harui");
Microsoft.Office.Interop.Outlook.Recipients sentTo = newAppointment.Recipients;
Microsoft.Office.Interop.Outlook.Recipient sentInvite = null;
sentInvite = sentTo.Add("Holly Holt");
sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olRequired;
sentInvite = sentTo.Add("David Junca ");
sentInvite.Type = (int)Microsoft.Office.Interop.Outlook.OlMeetingRecipientType.olOptional;
sentTo.ResolveAll();
newAppointment.Save();
newAppointment.Display(true);
}
catch (Exception ex)
{
//MessageBox.Show("The following error occurred: " + ex.Message);
}
}
Here's the article from Microsoft How to: Programmatically Create Appointments

Related

MyCustomPage.xaml is not loading webView in xamarin.Forms portable

I am beginner in xamarin.forms portable, i am working on xamainr.forms portable project, there i am facing issue. I have a .xaml page in my portable project and i am navigating to this .xaml page from App.cs using following line of code.
var ep = new CustomWebViewPage(dbPath);
var MainEv = new NavigationPage(ep);
Here in CustomWebViewPage i am using WebView in following way to load Url but after successful execution above lines emulator does not load webView. I don't know why it is happening.
I am pasting code of CustomWebViewPage as following.
CustomWebViewPage.xaml.cs
using XamarinDbokReader.SQLite_AppSample;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.IO;
namespace MyDummyProject
{
public partial class CustomWebViewPage : ContentPage
{
public string dbPath = "";
public CustomWebViewPage(string folderPath)
{
this.dbPath = folderPath;
HttpHelperClass helperClass = new HttpHelperClass();
InitializeComponent();
var webView = new WebView();
UrlWebViewSource urlWebViewSource = new UrlWebViewSource()
{
Url = UrlsList.FindUrl("ProEportalLoginPage") + UrlsList.ApiKeys(AppMode.ProductionMode.ToString())
};
webView.Source = urlWebViewSource;
webView.Navigated += (s, e) =>
{
if (e.Url.StartsWith("http://userInfo/?"))
{
string token = "";
try
{
string value_string = Uri.UnescapeDataString(e.Url.ToString());
token = value_string.Split('=')[1];
if (!string.IsNullOrEmpty(token))
{
string path = Path.Combine(dbPath.ToString(), "dBookStore.db3");
helperClass.SaveUserInformation(token, path);
}
}
catch (Exception ss)
{
}
}
};
wvEportalPage = webView;
}
public CustomWebViewPage()
{
}
}
}
CustomWebViewPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinDbokReader.EportalPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<WebView x:Name="wvEportalPage"></WebView>
</ContentPage>
App.cs
public App(bool isSqliteDbExist, string sPath)
{
isDbExist = isSqliteDbExist;
dbPath = sPath;
if (isDbExist)
{
if (isLoggedIn)
{
NavigationPage navPage = new NavigationPage(new BooksView());
App.Current.MainPage = navPage;
}
else
{
var tdlx = new CustomWebViewPage(dbPath);
var MainNave = new NavigationPage(tdlx);
}
}
else
{
//When cursor is coming from MainActivity then following line executes. And then OnStart() method executes.
ssd.CreateTablesInDb();
isDbExist = true;
}
}
protected override void OnStart()
{
if (isDbExist)
{
if (isLoggedIn)
{
NavigationPage navPage = new NavigationPage(new BooksView());
App.Current.MainPage = navPage;
}
else
{
var ep = new CustomWebViewPage(dbPath);
var MainEv = new NavigationPage(ep);
}
}
}
MainActivity
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
var documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var bookCoverFolder = Path.Combine(documents, "BooksCover");
var booksCollection = Path.Combine(documents, "Books");
var bookResource = Path.Combine(documents, "Resource");
if(!Directory.Exists(bookCoverFolder))
Directory.CreateDirectory(bookCoverFolder);
if (!Directory.Exists(booksCollection))
Directory.CreateDirectory(booksCollection);
if(!Directory.Exists(bookResource))
Directory.CreateDirectory(bookResource);
SQLite_Android androidDb = new SQLite_Android();
if (androidDb.IsExist())
{
LoadApplication(new App(true, androidDb.dbStorePath));
}
else
{
LoadApplication(new App(false, androidDb.dbStorePath));
}
}
The WebView probably isn't getting any Width or Height.
Try setting the VerticalOptions and HorizontalOptions properties to FillAndExpand.
So like this:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinDbokReader.EportalPage">
<Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
<WebView x:Name="wvEportalPage" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand"></WebView>
</ContentPage>
If that doesn't seem to work try wrapping it in a Grid.
Thank you for awesome sugessions, but i found my mistake in code.I did a very small mistake in App.cs After setting navigation page i am not setting NavigationPage to MainPage. It should as below.
var tdlx = new CustomWebViewPage(dbPath);
var MainNave = new NavigationPage(tdlx);
MainPage = MainNave;
it worked perfectly. I knew about MainPage but i have not written due to some other regions but ultimately it is working.
You must define Width and Height to Xamarin WebView.

Custom CommandBar to PickerFlyout

By default PickerFlyout has commandbar that has done and cancel buttons. Is it possible to disable done button programmatically? If not is there any way to add custom command bar and replace default one?
With the help of the answer given i tried to write custom picker from PickerFlyoutBase. But now i'm not able to add content to flyout in xaml. Giving me error saying custompicker doesnt support direct content
<Button>
<Button.Flyout>
<local:custompicker>
<TextBlock Margin="20" FontSize="30" Text="MyPickerFlyout Test" />
</local:custompicker>
</Button.Flyout>
</Button
public class custompicker:PickerFlyoutBase
{
private AppBar OriginalAppBar;
private CommandBar MyCommandBar;
private Page CurrentPage;
public custompicker()
{
var cancelButton = new AppBarButton();
cancelButton.Icon = new SymbolIcon(Symbol.Cancel);
cancelButton.Label = "Cancel";
cancelButton.Click += (s, e) =>
{
this.Hide();
};
MyCommandBar = new CommandBar();
MyCommandBar.PrimaryCommands.Add(cancelButton);
this.Closed += MyPickerFlyout_Closed;
this.Opening += MyPickerFlyout_Opening;
this.Placement = Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Full;
}
private void MyPickerFlyout_Opening(object sender, object e)
{
CurrentPage = (Windows.UI.Xaml.Window.Current.Content as Frame).Content as Page;
if (CurrentPage != null)
{
OriginalAppBar = CurrentPage.BottomAppBar;
CurrentPage.BottomAppBar = MyCommandBar;
}
}
private void MyPickerFlyout_Closed(object sender, object e)
{
if (CurrentPage != null)
{
CurrentPage.BottomAppBar = OriginalAppBar;
}
}
}
PickerFlyout class has a ConfirmationButtonsVisible property, we can use this property to disable both "Done" and "Cancel" button.
But there is no way to disable only "Done" button. We have to implement a custom "PickerFlyout". Following is a simple custom "PickerFlyout" based on Flyout, you can refer to it to implement your own.
public class MyPickerFlyout : Flyout
{
private AppBar OriginalAppBar;
private CommandBar MyCommandBar;
private Page CurrentPage;
public MyPickerFlyout()
{
var cancelButton = new AppBarButton();
cancelButton.Icon = new SymbolIcon(Symbol.Cancel);
cancelButton.Label = "Cancel";
cancelButton.Click += (s, e) =>
{
this.Hide();
};
MyCommandBar = new CommandBar();
MyCommandBar.PrimaryCommands.Add(cancelButton);
this.Closed += MyPickerFlyout_Closed;
this.Opening += MyPickerFlyout_Opening;
this.Placement = Windows.UI.Xaml.Controls.Primitives.FlyoutPlacementMode.Full;
}
private void MyPickerFlyout_Opening(object sender, object e)
{
CurrentPage = (Windows.UI.Xaml.Window.Current.Content as Frame)?.Content as Page;
if (CurrentPage != null)
{
OriginalAppBar = CurrentPage.BottomAppBar;
CurrentPage.BottomAppBar = MyCommandBar;
}
}
private void MyPickerFlyout_Closed(object sender, object e)
{
if (CurrentPage != null)
{
CurrentPage.BottomAppBar = OriginalAppBar;
}
}
}
Then you can use it in XAML like:
<Button Content="Show Picker">
<Button.Flyout>
<local:MyPickerFlyout Closed="PickerFlyout_Closed">
<TextBlock Margin="20" FontSize="30" Text="MyPickerFlyout Test" />
</local:MyPickerFlyout>
</Button.Flyout>
</Button>
And it looks like:

How to click “ok” in popup “Message from webpage” in selenium c#?

I have an application in which after clicking button, a popup comes titled Message from Webpage showing the error message.I want to click Ok button on it and verify the error message.
I tried the following code
public void clickButtonWithOk()
{
try
{
Thread.Sleep(Convert.ToInt32(GlobalVariables.WaitTime.ToString()) * 1000);
// Get element at runtime
inputData = "45";
waitForElementDisplayed();
int runTimeObjectSize = driver.FindElements(getApplicationObject(currentObjectName, currentObjectType, currentObjectUniqueId)).Count;
if (runTimeObjectSize == 0)
STEPLogger.logmessage(STEPLogger.FAIL, "FAILED to click button " + currentObjectName + " Object NOT Found");
else
{
IWebElement element = driver.FindElements(getApplicationObject(currentObjectName, currentObjectType, currentObjectUniqueId))[0];
IJavaScriptExecutor executor = (IJavaScriptExecutor)driver;
executor.ExecuteScript("window.confirm = function(msg){return true;};");
executor.ExecuteScript("arguments[0].click();", element);
STEPLogger.logmessage(STEPLogger.PASS, "SUCCESSFULLY clicked on button " + currentObjectName);
}
}
catch (Exception oException)
{
STEPLogger.logmessage(STEPLogger.FAIL, "FAILED clickButton:" + oException.ToString());
}
} // End of CLICKBUTTONWithOk

Telerik Export to Excel : Need to add an additional header containing HTML

I am using the below code for Exporting the Telerik Grid content to Excel.
COde is as following:
grdDisbursementDetail.Page.Response.ClearHeaders();
grdDisbursementDetail.Page.Response.Cache.SetCacheability(HttpCacheability.Private);
grdDisbursementDetail.ExportSettings.ExportOnlyData = true;
grdDisbursementDetail.ExportSettings.IgnorePaging = false;
grdDisbursementDetail.MasterTableView.HierarchyDefaultExpanded = true;
grdDisbursementDetail.ExportSettings.OpenInNewWindow = true;
grdDisbursementDetail.GridLines = GridLines.Both;
//grdDisbursementDetail.PageSize = grdDisbursementDetail.PageCount;
grdDisbursementDetail.ExportSettings.FileName = Common.GetLiteral("Report_DisbursementDetailReport_PDFExportFileName");
//grdDisbursementDetail.MasterTableView.Columns[0].Visible = false;
// grdDisbursementDetail.MasterTableView.DataSource = grdDisbursementDetail.Items;
grdDisbursementDetail.MasterTableView.ExportToExcel();
grdDisbursementDetail is a Telerik RadGrid.
I want to add a HTML in the header of the excel. Please do let me know if there is a way to add header.
Do you need a real page header or just some custom text in the beginning of the worksheet?
Custom text in the beginning of the sheet:
protected void RadGrid1_GridExporting(object source, GridExportingArgs e)
{
if (e.ExportType == ExportType.Excel)
{
string customText = "your text goes here";
e.ExportOutput = e.ExportOutput.Replace("<body>", "<body>" + customText);
}
}
Custom text in the page header:
protected void RadGrid1_HTMLExporting(object sender, GridHTMLExportingEventArgs e)
{
string headerText = "My header text";
string css = String.Format("table #page {{ mso-header-data:\"{0}\"; }}", headerText);
e.Styles.Append(css);
}
Good luck
You can try this from telerik foruns
MyGrid.MasterTableView.Caption = "<span style='font-size:22pt;'>TEXT</span>"

SharePoint 2010

We are working on an assignment to create a web application using SharePoint 2010 which is totally new to all of us.
My challenge is creating a file upload form. I used SharePoint designer to drag the upload texbox and button controls from the ASP.NET tool box. I don't know what to do next because I need the files to go where I want.
Here is the code that I have for the control I palced on the page:
<form id="form1" runat="server">
<asp:FileUpload runat="server" id="FileUpload1" /><br />
<br />
<asp:Button runat="server" Text="Upload" id="Button1" Width="88px" />
</form>
This routine will upload a single file assuming you've implemented the FileUpload control on your page. the routine gets the file name from the FileUpload control and adds it to a SharePoint list:
protected void UploadButton_Click(object sender, EventArgs e)
//=================================================
// upload the file selected in the upload button to the library
//
//=================================================
{
string docLibName = "/documents/Forms/AllItems.aspx";
if (FileUpload.HasFile)
{
try
{
int orderID = Convert.ToInt32(ViewState["OrderID"].ToString());
string status = ddlDocumentStatus.SelectedValue;
string docType = ddlDocumentType.SelectedValue;
// Read the file contents into a byte stream
string filename = FileUpload.FileName;
byte[] contents = new byte[FileUpload.FileContent.Length];
System.IO.Stream myStream;
int fileLen = FileUpload.PostedFile.ContentLength;
myStream = FileUpload.FileContent;
myStream.Read(contents, 0, fileLen);
// Upload the file to "Documents" Library
using (SPSite oSite = new SPSite(_siteURL))
using (SPWeb oWeb = oSite.OpenWeb())
{
docLibName = _siteURL + docLibName;
SPWeb site = new SPSite(docLibName).OpenWeb();
// Copy the file to the sharepoint library
SPFolder myLibrary = oWeb.Folders["Documents"];
// try checking out the file, if it doesn't exist, create it:
SPFile spfile = null;
try
{
spfile = oWeb.GetFile(_siteURL + "/Documents/" + filename);
if (spfile.Exists)
{
spfile.CheckOut();
myLibrary.Files.Add(filename, myStream, true);
}
else // create a new document
{
spfile = myLibrary.Files.Add(filename, myStream, true);
}
SPListItem document = spfile.Item;
// Copy the metadata to the document
//spfile.Item;
// update the metadata for the document here
document["Columns Name"] = some_string_value;
document["Document Type"] = docType;
myLibrary.Update();
document.Update();
spfile.CheckIn("Document updated on " + DateTime.Today.ToString());
}
catch (Exception ex)
{
string errorMessage = ex.Message;
}
// update the sharepoint list
SPList docLib = oWeb.Lists["Documents"];
AddDocuments(orderID, docLib);
lblDocumentMessage.Text = "Document uploaded!";
}// using - Disposes Site and web
}// try
catch (Exception ex)
{
string errorMessage = ex.Message;
lblDocumentMessage.Text = "Document upload error: " + errorMessage;
}
}
}