Hi I'm working to develop a solution to creating a toolbar in Outlook 2010 using VSTO 2012 and the microsoft outlook 2010 addin. In a nutshell I am able to create the Outlook ribbon and a button but I am unable to get the button to open an .oft file. In Visual Studio I get the following error "The name 'application' does not exist in the current context". I have added a reference to the Microsoft Office 14.0 Object Library also. Below is the code...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools.Ribbon;
namespace OutlookAddIn8
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void CreateItemFromTemplate()
{
Outlook.Folder folder =
Application.Session.GetDefaultFolder(
Outlook.OlDefaultFolders.olFolderDrafts) as Outlook.Folder;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"c:\ivy.oft", folder) as Outlook.MailItem;
mail.Subject = "Congratulations";
mail.Save();
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
}
}
}
Thanks any help is appreciated it is probably something simple thats been missed.
An instance of Application can be accessed using Globals.ThisAddIn.Application. If you renamed your AddIn class to something different e.g. MyAddIn then the command will be: Globals.MyAddIn.Application.
Here is a link with more details: http://msdn.microsoft.com/en-us/library/vstudio/bb157876(v=vs.100).aspx
Finally got there in the end, heres the code.....
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAddIn3
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Outlook.Application Application = Globals.ThisAddIn.Application;
Outlook.MailItem mail =
Application.CreateItemFromTemplate(
#"Z:\Transfer\Outlook 2010 Templates\testsubject.oft") as Outlook.MailItem;
mail.Display(true);
}
Related
I can download some files in a random page (a pdf from google, for example) but in the page I need to download them from, I get "Unsuccessful Download" notification on smartphone, with no exception thrown for me. Is there a way to know why this is happening?
Code from the renderer that I use to download below.
using Android.App;
using Android.Webkit;
using MPS.Libertas.Mobile.Droid.Renderers;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using Android.Content;
using Xamarin.Essentials;
using System.IO;
using System;
using Android.Widget;
using static Android.Provider.MediaStore;
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MPS_MyWebViewRenderer))]
namespace MPS.Libertas.Mobile.Droid.Renderers
{
internal class MPS_MyWebViewRenderer : WebViewRenderer
{
public MPS_MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
Control.Download += OnDownloadStart;
}
private void OnDownloadStart(object sender, Android.Webkit.DownloadEventArgs e)
{
try
{
var url = e.Url;
string url_formatted = url.Replace("blob:", "");
DownloadManager.Request request = new DownloadManager.Request(Android.Net.Uri.Parse(url_formatted));
request.AllowScanningByMediaScanner();
request.SetNotificationVisibility(DownloadVisibility.VisibleNotifyCompleted);
request.SetMimeType("application/pdf");
// if this path is not create, we can create it.
string thmblibrary = FileSystem.AppDataDirectory + "/download";
if (!Directory.Exists(thmblibrary))
Directory.CreateDirectory(thmblibrary);
request.SetDestinationInExternalFilesDir(Android.App.Application.Context, FileSystem.AppDataDirectory, "download");
DownloadManager dm = (DownloadManager)Android.App.Application.Context.GetSystemService(Android.App.Application.DownloadService);
dm.Enqueue(request);
}
catch (System.Exception ex)
{
var message = ex.Message;
throw;
}
}
}
}
I’m trying to establish a connection with a Web Service already running with Visual Studio 2019 community. The connection is already establish on Visual Studio but when trying to use it I got CS0119 error ‘UsuariosSoap’ is a type, which is not valid int given context.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using System.Net;
using UsuarioWS;
namespace XamarinWSMobile
{
// Learn more about making custom code visible in the Xamarin.Forms previewer
// by visiting https://aka.ms/xamarinforms-previewer
[DesignTimeVisible(false)]
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void AnadirUsuario(object sender, EventArgs e)
{
//establece la conexion con el web service
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
usuarioWS.GuardarUsuarioAsync(this.Nombre.Text, this.Apellidos.Text,this.Direccion.Text, this.Pueblo.Text, this.ZipCode.Text, this.FechaNac.Text);
}
}
}
That error is telling UsuariosSoap is a Type so this is wrong:
UsuarioWS.UsuariosSoap usuarioWS = UsuarioWS.UsuariosSoap;
In order to use it, you need to create an instance of the service, the UsuariosSoap class, before using it.
Replace the line above with this:
UsuarioWS.UsuariosSoap usuarioWS = new UsuarioWS.UsuariosSoap();
Hope this helps.-
I use Visual Studio 2005 to develop a "Windows Service" using c#.net. My code requires to access the MS office Clipboard. But on trying to access the Clipboard class, the debugger throws an error
"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
during the run-time. On checking for the solutions, I found that this could be solved by adding "[STAThread]" before the main method. But on adding this, I get a compilation error
"The type or namespace name 'STAThread' could not be found (are you missing a using directive or an assembly reference?)"
Is it possible to access the clipboard with my current version of .NET(.NET 3.0)?
The main method is in a file titled "program.cs" and the logic is in a file titled "Service.cs". Clipboard is used by Service.cs.
/* Program.cs */
using System.Collections.Generic;
using System.ServiceProcess;
using System.Text;
using System.Media;
using System.Threading;
namespace WindowsService1
{
static class Program
{
[STAThread]
static void Main(string[] args)
{
#if DEBUG
Service1 serv = new Service1();
serv.onDebug();
System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite);
#else
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] { new Service1() };
ServiceBase.Run(ServicesToRun);
#endif
}
}
}
/* Service.cs */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Threading;
using System.Timers;
namespace WindowsService1
{
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
public void onDebug()
{
OnStart(null);
}
protected override void OnStart(string[] args)
{
clear_cb();
}
protected void clear_cb()
{
Clipboard.Clear(); // This is the line where I get the exception
}
protected override void OnStop()
{
// TODO: To clear the back up Database
}
}
}
I'm writing my first app for windows phone, which will be a sound board, using XNa's soundeffect object.
The project is a Windows phone Silverlight and Xna Application c#
I got some sample code from the book, 101 phone 7 apps.
The linbe to load in the sound gives me a
"the type StreamResourceInfo namespace could not be found"
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
the code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Xna.Framework.Audio;
namespace SlXnaApp4
{
public partial class MainPage : PhoneApplicationPage
{
SoundEffect cowbell;
// Constructor
public MainPage()
{
// Load sound file
StreamResourceInfo info = Application.GetResourceStream(new Uri("Audio/cowbell.wav", UriKind.Relative));
// create xna sound
cowbell = SoundEffect.FromStream(info);
// Sub to per frame call back
CompositionTarget.Rendering += CompositionTarget_Rendering;
// requred for xna sound effects to work
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
// testb sound
cowbell.Play();
InitializeComponent();
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
Microsoft.Xna.Framework.FrameworkDispatcher.Update();
}
// Simple button Click event handler to take us to the second page
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/GamePage.xaml", UriKind.Relative));
}
private void button1_Click(object sender, RoutedEventArgs e)
{
}
}
}
Add a using directive for System.Windows.Resources:
using System.Windows.Resources;
i'm working on a windows phone 7 emulator. I have a web browser which navigates to local host. So my problem i faced was that when i tilt the windows phone 7 emulator 90% right, the screen doesn't. Could there be any advice on how to do so?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
namespace DSP
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
}
private void ContentPanel_Loaded(object sender, RoutedEventArgs e)
{
MessageBox.Show("Loading website. This might take a few seconds...");
webBrowser1.Navigate(new Uri("http://localhost/Liweiyi_fyp_082648y/homepage.html", UriKind.Absolute));
}
private void webBrowser1_Loaded(object sender, RoutedEventArgs e)
{
}
}
}
Check your SupportedOrientations is PortraitOrLandscape in your xaml.
Also check your emulator isn't orientation locked due to hardware keybaord emulation. Restart it if you're not sure how to fix that.
I believe you're looking for how to handle orientation changes on the phone?
You're looking to change the following in the .xaml for the appropriate page - most likely MainPage.xaml:
Change the highlighted line to read
SupportedOrientations="PortraitOrLandscape"
And in case that wasn't enough information, here's a helpful blogpost.