Server unable to execute EWS autodiscover - c#

On our testing server, EWS autodiscover does not work. To eliminate an ill-set IIS option from the list of causes, I C&P'ed together a WindowsForms Application (code below) and put it, together with the Microsoft.Exchange.Webservice.dll, into a folder on which I have write permission.
Unfortunately, neither xml nor text file are created. Instead, I get an Unhandled Exception error.
System.NullReferenceException
at System.Windows.Forms.TextBoxBase.AppendText(String text)
This does not happen on my development machine, which is in the same AD domain and on which the test app always returns that autodiscover was successful.
Question: How come no Trace output is generated?
So now, my app code:
Form1.cs
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;
using Microsoft.Exchange.WebServices;
using Microsoft.Exchange.WebServices.Data;
namespace ADDebugWin
{
public partial class Form1 : Form
{
public static string traceData;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ExchangeService ews = new ExchangeService(ExchangeVersion.Exchange2010);
ews.TraceListener = new TraceListener();
// Optional flags to indicate the requests and responses to trace.
ews.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;
ews.TraceEnabled = true;
ews.UseDefaultCredentials = true;
try {
ews.AutodiscoverUrl("email#mydomain.com");
textBox1.AppendText("AutoDiscover erfolgreich.");
} catch (Exception ex) {
textBox1.AppendText(traceData);
textBox1.AppendText(ex.Message + "\r\n" + ex.StackTrace);
}
}
}
}
TraceListener.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ADDebugMvc.Controllers;
using Microsoft.Exchange.WebServices.Data;
using System.Xml;
namespace ADDebugMvc.Models
{
class TraceListener : ITraceListener
{
public void Trace(string traceType, string traceMessage)
{
CreateXMLTextFile(traceType, traceMessage.ToString());
HomeController.traceData += traceType + " " + traceMessage.ToString() + "\r\n";
}
private void CreateXMLTextFile(string fileName, string traceContent)
{
// Create a new XML file for the trace information.
try
{
// If the trace data is valid XML, create an XmlDocument object and save.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(traceContent);
xmlDoc.Save(fileName + ".xml");
}
catch
{
// If the trace data is not valid XML, save it as a text document.
System.IO.File.WriteAllText(fileName + ".txt", traceContent);
}
}
}
}

One should note that
ews.TraceFlags = TraceFlags.EwsRequest | TraceFlags.EwsResponse;
is not returning any Traces during AutoDiscover.
(ews.TraceFlags = TraceFlags.All; does.)
So no string is appended to traceData, which is why traceData==null -> Exception when appending it to a TextBox.

Related

C# and GDAL implementation - Dataset not returning a value

I am trying to automate a simple geotiff to KMZ process using GDAL and C#
The code I have written is a little buggy and I am having a lot of trouble working out how to use the API. I am hoping this is a simple fix for more advanced developers.
My code is as follows:
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OSGeo.GDAL;
namespace TestingTIFFtoKMZ
{
class Program
{
static void Main(string[] args)
{
string outputName = Environment.CurrentDirectory + #"\BR01899_Mackenzie_09_EXPORT";
string vrtfile = outputName + #"\tempMosaic.vrt";
string filenameKMZ = outputName + #"\" + Environment.CurrentDirectory + ".kmz";
string[] tiffFiles = Directory.GetFiles(outputName, "*.tif");
var vrtOptions = new GDALBuildVRTOptions(new[] { "-overwrite" });
GDALTranslateOptions transOptions = new GDALTranslateOptions(new[] { "-of", "KMLSUPEROVERLAY", "-co", "format=png" });
Dataset vrtDataset = Gdal.wrapper_GDALBuildVRT_names(vrtfile, tiffFiles, vrtOptions, null, null);
// vrtDataset.Dispose();
Gdal.wrapper_GDALTranslate(filenameKMZ, vrtDataset, transOptions, null, null);
}
}
}
I am getting a null return value on the vrtDataset variable and (i think) as a result, I am getting a null reference error when I call the Gdal.wrapperGDALTranslate method.
Any help appreciated. Thanks.
It needed,
Gdal.AllRegister();
and an absolute path to the VRT file being created.

System.UnauthorizedAccessException C# Windows 10 Phone Emulator

I know there is a bunch of threads on seemingly the same issue but I cannot for the life of me figure this out after 3 hours so I really need some help.
I understand that I am getting this error because the system does not have access to the file. I have tried setting permissions to full and a few other code snippets to solve my issue but none have worked.
This is a windows 10 app using Xaramin,
I am trying to populate a listbox with contact from an XML file. I have the list box itemsSource set to "Data Context" and path "myList". The XML build action is set to "Content" and the Copy to Output Directory Set to "Copy Always".
I have attempted to follow the tutorial from my course from the beginner 3 times and always get the same error.
Here is the error I am getting
Below is the entire code on the page.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using System.Xml;
using System.Xml.Linq;
using Windows.Storage;
using System.Collections.ObjectModel;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace ContactsApp
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
string TEMPFILEPATH = "";
string TARGETFILEPATH = "";
private ObservableCollection<string> lstd = new ObservableCollection<string>();
public ObservableCollection<string> myList { get { return lstd; } }
public MainPage()
{
this.InitializeComponent();
}
private void Grid_Loading(FrameworkElement sender, object args)
{
Windows.ApplicationModel.Package package = Windows.ApplicationModel.Package.Current;
StorageFolder installedLocation = package.InstalledLocation;
StorageFolder targetLocation = ApplicationData.Current.LocalFolder;
TEMPFILEPATH = installedLocation.Path.ToString() + "\\Contacts.xml";
TARGETFILEPATH = targetLocation.Path.ToString() + "\\Contacts.xml";
File.Move(TEMPFILEPATH, TARGETFILEPATH);
loadContacts();
}
private void loadContacts()
{
XmlReader xmlReader = XmlReader.Create(TARGETFILEPATH);
while (xmlReader.Read())
{
if (xmlReader.Name.Equals("ID") && (xmlReader.NodeType == XmlNodeType.Element))
{
lstd.Add(xmlReader.ReadElementContentAsString());
}
}
DataContext = this;
xmlReader.Dispose();
}
}
}
I will be eternally grateful for any help regarding the matter. :)
You should not try to access restricted paths in constrained environments (like Windows Phone).
Instead, if you really need to embed this file with your application, change the build action to Embedded Resource and to Do not copy for your xml file, and then retrieve the resource inside your code as an Embedded Resource:
public void LoadContacts()
{
const string fileName = "Contacts.xml";
var assembly = typeof(MainPage).GetTypeInfo().Assembly;
var path = assembly.GetManifestResourceNames()
.FirstOrDefault(n => n.EndsWith(fileName, StringComparison.OrdinalIgnoreCase));
if(path == null)
throw new Exception("File not found");
using (var stream = assembly.GetManifestResourceStream(path))
using (var reader = XmlReader.Create(stream))
{
while (reader.Read())
{
if (reader.Name.Equals("ID") && (reader.NodeType == XmlNodeType.Element))
{
lstd.Add(reader.ReadElementContentAsString());
}
}
}
DataContext = this; // better to move this inside the constructor
}

"File.Exists" does not exist

I created this class "XML_Toolbox" that could be used by any of my forms to perform any of the key XML actions that i am going to be using repeatedly. So with that being said, here is that class' code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Windows.Forms;
namespace Personal_Finance_Manager
{
class XML_toolbox
{
public static void createFile (string filename, string filePath)
{
string createPath = filePath + #"\" + filename + ".txt";
if (file.exists(createPath))
{
StreamWriter outfile = new StreamWriter(createPath, true);
}
else
{
MessageBox.Show("This file already exists!!! Please choose another name!");
}
}
}
}
all the individual parts were working when called from another form up until i added the:
if (file.exists(createPath)) {}
IF statement.
Now i am getting the
The name "file" does not exist in the current context
error. I have the
using System.IO;
what else am i missing?
Thanks!
Class name is File not file, method name is Exists. C# is case-sensitive.
It's called File, not file.
File.Exists()

How to give Common path to video

I am working in project in which I have used vlc plugin v2. the path for my video is
axVLC.playlist.add(#"D:\My Project\Science\Resources\myvideo.mp4");
axVLC.playlist.play();
now the problem is when I build the project and give it to someone and he/she install it on his/her computer , it show exception that video path is wrong. I am sure that path is not suitable as my the video path in my project is D:... and he/she installed it on C.
So my question is that is there any way to give it common path by which user don`t face such kind of error
Import IO
Using System.IO;
then declare a string that will reference to your video folder
string AbsoluteRef;
use this code in your form load
if (System.Diagnostics.Debugger.IsAttached)
{
AbsoluteRef = Path.GetFullPath(Application.StartupPath + "\\..\\..\\Resources\\");
}
else
{
AbsoluteRef = Application.StartupPath + "\\Resources\\";
}
Now declare a string for your video or which ever file like
string vlcvideo;
now add the two together
vlcvideo = AbsoluteRef & "myvideo.mp4";
Finnally add all this into your vlc plugin
axVLC.playlist.add(vlcvideo);
Complete Code looks like so.
using Microsoft.VisualBasic;
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;
using System.Windows.Input;
using yournamespace.Forms;
using System.IO;
namespace yourNameSpace
{
public partial class frmMain : Form
{
public frmMain()
{
InitializeComponent();
}
string AbsoluteRef = null;
private void frmMain_Load(object sender, EventArgs e)
{
if (System.Diagnostics.Debugger.IsAttached)
{
AbsoluteRef = Path.GetFullPath(Application.StartupPath + "\\..\\..\\Resources\\");
}
else
{
AbsoluteRef = Application.StartupPath + "\\Resources\\";
}
string vlcVideo = AbsoluteRef + "myvideo.mp4";
axVLC.playlist.add(vlcvideo);
}

using Microsoft Translate ( GetTranslation Service )

I'm going to build website that uses the translation service from Microsoft. I need to get all the available translations for each word but the code I have provides only one translation while it is supposed to give all available translations. Here's the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using microsofttranslator;
using System.Text;
using System.Net;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Runtime.Serialization;
using System.ServiceModel.Channels;
using System.ServiceModel;
using TranslatorService;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{string Appid="my Appid";
string t="any text";
microsofttranslator.TranslateOptions options = new microsofttranslator.TranslateOptions();
options.Category = "general";
options.ContentType = "text/plain";
options.User = "TestUserId";
options.Uri = "";
bool a=true;
SoapService s = new SoapService();
microsofttranslator.GetTranslationsResponse translations = s.GetTranslations(Appid, t, "ar", "en", 5,a, options);
Response.Write(string.Format("Available translations for source text '{0}' are", t));
foreach (microsofttranslator.TranslationMatch translationMatch in translations.Translations)
{
Response.Write(string.Format("Translated text: {0}" + Environment.NewLine + " Rating:{1}" + Environment.NewLine + "Count:{2}" + Environment.NewLine, translationMatch.TranslatedText, translationMatch.Rating.ToString(), translationMatch.Count.ToString()));
} }}
I added Microsft translate WSDL as a web reference http://api.microsofttranslator.com/v2/Soap.svc?wsdl and I added TranslatorService as a service reference http://api.microsofttranslator.com/V2/Soap.svc
This code works well but as I said it gives only one translation while it is supposed to give all the available translations of a word. I cannot figure out what I am doing wrong.
Maybe you should use the "translateArray" method.
http://msdn.microsoft.com/en-us/library/ff512438.aspx

Categories