Outlook VSTO code crashes when click on the button for image - c#

I am working on this Outlook VSTO Add-on, to add an image in the body of the email, but no luck at all for two weeks!!! It works with a normal path like c:\folder
but it doesn't work if I want to use the Resources folder inside of the app.
When I run it and click on the button, it crashes and goes to the:
document.Application.Selection.InlineShapes.AddPicture(ImagePath);
There is a Ribbon with a button. When user clicks, it should add the email signature in the body.
PLEASE HELP!!!!!!!!!!!!!!!!
private void button_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
Word.Document document = inspector.WordEditor;
string ImagePath = #"\Resources\Picture.jpg";
if (document.Application.Selection == null)
{
MessageBox.Show("Please select the email body");
}
else
{
document.Application.Selection.InlineShapes.AddPicture(ImagePath);
}
}

Word Object Model knows nothing about resources inside your assembly. It does not know and does not care about any external assemblies. It only understands files - you will need to extract the resource into a temp file and specify that file's fully qualified file name.

Related

Why doesn't a pdf file view in a seperate tab in internet explorer?

I have a function which display a pdf file. Im using Internet Explorer and it's upto date. I tried to do it in two computers. In one browser it asks to open through a pdf reader while other one opens a tab and display an empty page. I've tried many codes found in the internet even in stackoverflow. But nothing works as i want. Here i have added my code. Please take a look at it.
Linkbutton click event
protected void pdfViewLOP_Click(object sender, EventArgs e)
{
Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "viewPDF.aspx"));
}
code in new page which pdf should be displayed
protected void Page_Load(object sender, EventArgs e)
{
try
{
string name = Session["name"].ToString();
string FilePath = Server.MapPath("~/filesPDF/" + name);
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(FilePath);
if (buffer != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
It is likely due to settings on the client machine, specifically Adobe preferences.
To change the default PDF open behavior when using a web browser:
Choose Edit—>Preferences
Select the Internet category from the list on the left
To display the PDF in the browser, check "Display in browser"
To open PDFs from the web directly in Acrobat, uncheck "Display in browser:
See this article and this article.
Also note: To display a PDF in your browser, your cache control headers must allow the browser to create a temporary copy of the PDF. If you are setting cache hints to prevent caching (e.g. if you application contains sensitive pages) you might be better off letting the user download the PDF and view it offline.

Outlook - Custom Add-In Button for "Save and Send"

I am fairly new to C# as well as the Outlook Library. I've spent the past two weeks searching around reading documentation and examples yet I can't seem to achieve this simple (or so it seems) task.
The Intention:
The idea is to have a custom button that only appears in the ribbon of the New Mail window and when clicked, will prompt the user to choose an Outlook Folder. After the user chooses a folder and clicks OK, it will send the email and save a copy in the specified folder as well as the sent folder.
I am aware that currently, it is possible to specify which folder you want to save the outgoing message in. However, this will only save a copy in the specified folder, and not an additional copy in the Sent Items folder.
The Current Situation:
What I have currently will make a copy of the current email, move it to the specified folder, and send the original. However, the copied email will not show up as an email that's been sent. It is still editable which is not exactly what I am aiming for.
private void button1_Click(object sender, RibbonControlEventArgs e) {
MessageBox.Show("Save and Send button was clicked.");
Outlook.Application application = new Outlook.Application();
Outlook.Explorer explorer = application.ActiveExplorer();
Outlook.Inspector inspector = application.ActiveInspector();
Outlook._MailItem mailItem = inspector.CurrentItem;
Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
MessageBox.Show("Select a location to save the email");
Outlook.MAPIFolder folder = (Outlook.Folder)nameSpace.PickFolder();
Outlook._MailItem newMailCopy = mailItem.Copy();
newMailCopy.Move(folder);
mailItem.Send();
MessageBox.Show(newMailCopy + " was copied to " + folder);
}
I am creating a Ribbon (Visual Designer) in Visual Studio 2013 for an Outlook 2013 Add-In. What would be the best way to do this in C#?
Any help would be greatly appreciated! Regards,

Form Regions for Outlook and VSTO remove WebViewPane

I have just purchased: http://www.add-in-express.com/outlook-regions/
The reason why I have purchased that product is because I need to show a custom form on the main view of outlook when a specific folder is selected. I have managed to do so by doing the following:
Create a new Project int visual studio of type (Outlook 2010 Add-in)
Once that project is created I add:
Because I want that form to show on the main folder view of mail (replace all other views) I select this option:
I click next and follow all the defaults in order to create the form.
Once that form is created I add the buttons and images I need. In this example I will just add a button.
when I then run outlook and select my inbox folder this is what shows up:
(In other words every time I select a folder of type olMailItem that form shows up)
So now I solve my goal to display my custom form on the "main view of outlook"
Now my question is how can I show that form only on specific folders. For example I do not want to show that form when the folder "Inbox" is selected but I do want to show it when the folder "Outbox" is selected for example
Let's try to hide the form and show the default view when the button is clicked.
In order to solve that problem I have looked at: http://www.add-in-express.com/forum/read.php?FID=5&TID=4540
I have done the same steps but the form shows up again! In other words the code behind of the button looks like:
private void button1_Click(object sender, EventArgs e)
{
// get current folder in this case its inbox the one that is selected
MAPIFolder currentFolder = Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder;
Globals.ThisAddIn.ADXOlForm1Item.FolderName = string.Empty;
// clear web properties DO NOT SHOW WEB VIEW
currentFolder.WebViewURL = string.Empty;
currentFolder.WebViewOn = false;
// RESET FOLDER BY SELECTING A DIFFERENT ONE THEN THE SAME ONE
NameSpace nameSpace = Globals.ThisAddIn.Application.GetNamespace("MAPI");
MAPIFolder outboxFolder = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderOutbox);
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = outboxFolder; // CHANGE FOLDER TO A DIFFERNT ONE
System.Windows.Forms.Application.DoEvents();
Globals.ThisAddIn.Application.ActiveExplorer().CurrentFolder = currentFolder; // SET INBOX AGAIN
}
when I run that code the default view shows up for 1 second then it get's replaced with the form!
-------------------------------------------Edit-------------------------------------------
When I add the form region Addin Express adds a ADXOlFormsManager and a ADXOlFormsCollectionItem for the form that I created. Based on your answer I have done:
#region ADXOlForm1
// TODO: Use the ADXOlForm1Item properties to configure the region's location, appearance and behavior.
// See the "The UI Mechanics" chapter of the Add-in Express Developer's Guide for more information.
ADXOlForm1Item = new ADXOlFormsCollectionItem();
ADXOlForm1Item.FolderName = "MyCustomFolder"; // <---- ADDED THIS LINE HOPING TO SHOW THIS FORM ONLY WHEN THAT FOLDER IS SELECTED
ADXOlForm1Item.ExplorerLayout = ADXOlExplorerLayout.WebViewPane;
ADXOlForm1Item.ExplorerItemTypes = ADXOlExplorerItemTypes.olMailItem;
ADXOlForm1Item.UseOfficeThemeForBackground = true;
ADXOlForm1Item.FormClassName = typeof(ADXOlForm1).FullName;
this.FormsManager.Items.Add(ADXOlForm1Item);
#endregion
I was hoping for that form to only show up in MyCustomFolder but it does shows up when selecting any folder of type ADXOlExplorerItemTypes.olMailItem. Perhaps I am doing something wrong....
In other words I was hoping for only the MAPIFolder MyCustomFolder folder had the properties
WebViewOn=true;
WebViewURL = "...AppData\Local\Temp\AddinExpress\ADXOlFormGeneral.html"
but as I traverse all the folders in outlook I can see that all of them have those properties even after specifying ADXOlForm1Item.FolderName = "MyCustomFolder";
Thank you for choosing Add-in Express Regions.
I understand the "main view of outlook" as the folder that Outlook shows when it is started. By default, that folder is the top-level folder of the message store. Note that this can be changed, see File | Options | Advanced | Start Outlook in this folder. I use this setting so that my Outlook shows me the Inbox at start-up.
The below is a citation from the section Context-Sensitivity of Your Outlook Form, see see the PDF file in the folder {Add-in Express}\Docs\ on your development PC:
ADXOlFormsCollectionItem provides a number of properties that allow specifying the context settings for your form. Say, you can specify item types for which your form will be shown. Note that in case of explorer, the item types that you specify are compared with the default item type of the current folder. In addition, you can specify the names of the folders for which your form will be shown in the FolderName and FolderNames properties; these properties also work for Inspector windows – in this case, the parent folder of the Outlook item is checked. An example of the folder path is "\Personal Folders\Inbox".
A special value in FolderName is an asterisk ('*'), which means "all folders". You can also specify message class(es) for which your form will be shown. Note that all context-sensitivity properties of an ADXOlFormsCollectionItem are processed using the OR Boolean operation. That is, specifying e.g. folder names extends, but not limits, the list of contexts for which your form will be shown.
That is, if you need to show the form for a given folder, specify the path to that folder in the FolderName/*FolderNames* property.
Regards from Belarus (GMT+3),
Andrei Smolin, Add-in Express Team Leader

How to set the Selected item in the tree view on the Left side of CHM file

I have a CHM helpfile for my WPF Application. My CHM file contains "htm" files for each page of my application. I want to open the help file for the corresponding page when the user presses F1 on that page. Right now I am able to locate the page and open that page by using the following code:
Help.ShowHelp(this, helpfile, keywordText);
where keywordText contains the URL of my htm file for the selected page.
But the problem is, that the panel on the left side (contents tab in a tree view) is not expanded to the page that opened in the right window. The panel on the left side always remains the same.
How Can I expand the tree view on the left side to the selected page?
Have a look at the code and the small GUI (snap attached). The topics are refreshed after the users button click (e.g. Help Topic1).
Please note the help file created with Microsoft HTMLHelp Workshop may need a auto sync parameter.
private void btnHelpTopic1_Click(object sender, EventArgs e)
{
// sHTMLHelpFileName_ShowWithNavigationPane = "CHM-example_ShowWithNavigationPane.chm"
// This is a HelpViewer Window with navigation pane for show case only
// created with Microsoft HTMLHelp Workshop
helpProvider1.HelpNamespace = Application.StartupPath + #"\" + sHTMLHelpFileName_ShowWithNavigationPane;
Help.ShowHelp(this, helpProvider1.HelpNamespace, #"/Garden/tree.htm");
}
private void btnHelpTopic2_Click(object sender, EventArgs e)
{
helpProvider1.HelpNamespace = Application.StartupPath + #"\" + sHTMLHelpFileName_ShowWithNavigationPane;
Help.ShowHelp(this, helpProvider1.HelpNamespace, #"/Garden/flowers.htm");
}
For download I provide a C# VS2008 Project including the code above and the help files with different help viewer windows (different CHM files for show case only).
Thanks.
The Problem is in the URL.
Before that I gave a URL like this
"Help.CHM::/html/MyHelp.htm"
And when I removed "Help.CHM::/" from the URL and Everything Worked Well..

C# : upload file to a file host

i have been trying to upload a file to Fileshawk.com from my application.
Here is how i did it :
1- Created a web browser control
2- Loaded the page
3- in the web page it has an input tag of file.
4- i tried to add the file to HTML by using that method which failed.
private void Set_Text_TAG_INPUT(string attribute, string attname, string value)
{
// Get a collection of all the tags with name "input";
HtmlElementCollection htmle = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement current in htmle)
{
if (current.GetAttribute(attribute).Equals(attname))
{
current.SetAttribute("value", value);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Set_Text_TAG_INPUT("id","upfile_1342028154587", "FILE.txt");
}
So it didn`t change the value of the Input tag.
Is there any way to add my file to the HTML or page code and about pressing upload i already have a method that invokes the web browser button and click it.
For example , when you click Select file from the input file tag , a window pop up and you select the file , now when you click okay , where is that file stored in the HTML ?
Finally excuse me if i am a newbie in HTML and web knowledge.
This is a security feature in browsers. You cannot programmatically set the value of the value of an input tag of type 'file' since it would introduce a security hole (e.g. a malicious developer could set the value right before handling a submit event and get whatever file they wanted).
Use WebScraper, a C# .NET library to upload file/download file easily, but you need to analyze Fileshawk.com HTML to come up with your own WebScraper syntax, there are totally 22 file host syntax available for sample and already useable.
http://sorainnosia.com/Home/Article/WEBSCRAPER

Categories