I try to filter custom properties get contacts in a Outlook. I saved user property call "SyncValue". It have string values. And I try to check these values and get the contactitem have that property value.
Outlook.ContactItem contactItem = null;
string syncVal = (char)34 + "http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/SyncValue" + (char)34;
Outlook.MAPIFolder contacts = Globals.objNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items contactItems = contacts.Items;
string filter = "WHERE (" + syncVal + " = 'True')";
contactItem = contactItems.Find(filter) as Outlook.ContactItem;
Your filter string must be prefixed with #SQL=. You should not use "WHERE":
string filter = "#SQL=" + syncVal + " = 'True')";
Related
I'm having a lot of trouble trying to get my App to work when
published. Basically, the code is supposed to create a doc from
template using Open XML sdk, then save to wwwroot and then upload to
blob storage.
It's working fine using local host. Have read and tried some stuff re
accessing static files - but nothing seems to work. Any help would be
very much appreciated. Relevant code is below:
[HttpGet]
public IActionResult GenerateDocxBrowser(MemoryStream mem, string filepath, string inputLastName, string inputTitle, string requestID, string dateReceived, string complaintType, string complaintDetails, string nameString, string no, string street, string town, string postcode)
{
var list = _context.Complaints.Where(s => s.ComplaintId.ToString().Contains(requestID)).ToList();
using (mem = new MemoryStream())
{
filepath = #"wwwroot\RequestTemplate.docx";
nameString = list.Select(s => s.NameString).FirstOrDefault();
complaintDetails = list.Select(s => s.Complaint).FirstOrDefault();
street = list.Select(s => s.AddressStreet).FirstOrDefault();
town = list.Select(s => s.AddressTown).FirstOrDefault();
using (WordprocessingDocument document = WordprocessingDocument.Open(filepath,true))
{
document.GetMergeFields("LastName").ReplaceWithText(inputLastName);
document.GetMergeFields("Title").ReplaceWithText(inputTitle);
document.GetMergeFields("ComplaintID").ReplaceWithText(requestID);
document.GetMergeFields("DateReceived").ReplaceWithText(dateReceived);
document.GetMergeFields("ComplaintType").ReplaceWithText(complaintType);
document.GetMergeFields("ComplaintDetails").ReplaceWithText(complaintDetails);
document.GetMergeFields("NameString").ReplaceWithText(nameString);
document.GetMergeFields("AddressLn1").ReplaceWithText(no + " " + street);
document.GetMergeFields("AddressLn2").ReplaceWithText(town + " TAS " + postcode);
document.SaveAs(#"wwwroot\" + requestID + ".docx");
document.MainDocumentPart.Document.Save();
document.Close();
}
}
const string StorageAccountName = "xxx";
const string StorageAccountKey = "xxxxxx";
var storageAccount = new CloudStorageAccount(
new StorageCredentials(StorageAccountName, StorageAccountKey), true);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("tasman/Request Images");
CloudBlockBlob blockBlob = container.GetBlockBlobReference(requestID + ".docx");
blockBlob.UploadFromFileAsync(#"wwwroot\" + requestID + ".docx");
return View();
}
Your .SaveAs() field should be relative, currently its literally saving to wwwroot somewhere on the drive. You can specify the relative path a few different ways - one of them is below:
var saveToFolder = Path.Combine(Environment.CurrentDirectory, $"/wwwroot/{requestID}.docx");
I tried using the licenseCloud API but was una ble to get it right, the only guess I came to was the fact that I obtained an XML and a link to that XML "https://secure.licenseapi.com/?token=73af9d231e354e2c9ba30a72fdc68341b88613c1&sku=EXAMPLE&license=e59d6fd6629044f4ace4", so I took the link, placed in a textbox and on a buttonclick fires.
XDocument csvDocument = XDocument.Load(txtActivateFromSite.Text);
var samples = csvDocument.Descendants("license")
.Select(el => new
{
Id = el.Element("dashed").Value,
Selected = el.Element("status").Value,
Selected1 = el.Element("trial").Value,
Selected2 = el.Element("expires").Value,
Selected3 = el.Element("activated").Value
});
string dashed = ""; string status = ""; string trial = ""; string expires = ""; string activated = "";
foreach (var sample in samples)
{
dashed = sample.Id;
status = sample.Selected;
trial = sample.Selected1;
expires = sample.Selected2;
activated = sample.Selected3;
}
MessageBox.Show("your Application has been activate with License Number " + dashed + " on " + activated + " expires on "+
expires + ".");
Somehow I incoporated it to get something, please anymore ideas on how to use licensecloud
Appears you've forgotten the CMD parameter on your link:
&cmd=activate...
Also, you can download some sample code here (in PHP). Will give you a good idea on how to get it to work:
https://www.licensecloud.com/2015/04/10/licensecloud-protect-web-page/
am trying to develop a c# standalone application and my insert code has no error but when i click it will insert to first table or crtPro perfectly but it didn't add to the second table , can anyone give me some hint...???
here is my code for insert code...
private void button1_Click(object sender, EventArgs e)
{
System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
conn.ConnectionString = #"Provider=Microsoft.ACE.OLEDB.12.0;" +
#"Data source= C:\Documents and Settings\abel\My Documents\Visual Studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\crt_db.accdb";
try
{
conn.Open();
String Name = txtName.Text.ToString();
String Address = txtAddress.Text.ToString();
//String Wereda = txtWereda.Text.ToString();
//String Kebele = txtKebele.Text.ToString();
//String House_No = txtHouse.Text.ToString();
//String P_O_BOX = txtPobox.Text.ToString();
String Tel = txtTel.Text.ToString();
//String Fax = txtFax.Text.ToString();
String Email = txtEmail.Text.ToString();
String Item = txtItem.Text.ToString();
String Dep = txtDep.Text.ToString();
String Status = ToString();
String Remark = txtRemark.Text.ToString();
String Type = txtType.Text.ToString();
String Brand = txtBrand.Text.ToString();
String License_No = txtlicense.Text.ToString();
String Date_issued = txtDate.Text.ToString();
String my_querry = "INSERT INTO crtPro(Name,Address,Email,Tel,Item,Dep,Status,Remark)VALUES('" + Name + "','" + Address + "','" + Email + "','" + Tel + "','" + Item + "','" + Dep + "','" + Remark + "')";
OleDbCommand cmd = new OleDbCommand(my_querry, conn);
cmd.ExecuteNonQuery();
conn.Close();
conn.Open();
String my_querry1 = "SELECT LAST(PID) FROM crtPro";
OleDbCommand cmd1 = new OleDbCommand(my_querry1, conn);
string var = cmd1.ExecuteScalar().ToString();
//txtStatus.Text = var;
String PID = ToString();
String my_querry2 = "INSERT INTO crtItemLicense(PID,Type,Brand,License_No,Date_issued)VALUES('" +PID + "','" + Type + "','" + Brand + "','" + License_No + "','" + Date_issued + "')";
OleDbCommand cmd2 = new OleDbCommand(my_querry2, conn);
cmd2.ExecuteNonQuery();
MessageBox.Show("Message added succesfully");
}
catch (Exception ex)
{
MessageBox.Show("Failed due to" + ex.Message);
}
finally
{
conn.Close();
}
}
There are a couple of calls like:
String PID = ToString();
That will try to get a string representation of 'this', which is your form. That is probably not what you want to be inserting into the database. You probably meant
String PID = var.ToString();
If that isn't it, then try putting more tracewrites (or using a debugger) to narrow the problem down to find which one of your sql statements is causing the problem.
Also once you have it working, try entering this in the name field of your form:
Robert"); DROP TABLE crtPro;--
and then do some googling about SQL injection (apologies to XKCD).
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to Capitalize names using C#
How can i retrieve values from database tables in First letter capital format?
My LINQ Query is like this,
DBEntities Context = new DBEntities ();
var UserNameEntity = (from a in Context.UserInformation
where a.UserId == UserId
select a).First();
string UserName = UserNameEntity.FirstName + " " + UserNameEntity.LastName;
return UserName;
I am getting user name : bhargav soni
but i want this should be like Bhargav Soni
How can i do that?
This question is not related to LINQ, but a way that you could do this would be
TextInfo myTI = CultureInfo.CurrentCulture.TextInfo;
DBEntities Context = new DBEntities ();
var UserNameEntity = (from a in Context.UserInformation
where a.UserId == UserId
select a).First();
string UserName = string.Format("{0} {1}", myTI.ToTitleCase(UserNameEntity.FirstName), myTI.ToTitleCase(UserNameEntity.LastName));
return UserName;
On your FirstName and LastName properties, use the indexer to retrieve the first character, and call the Substring() method to retrieve the rest of the string.
DBEntities Context = new DBEntities ();
var UserNameEntity = (from a in Context.UserInformation
where a.UserId == UserId
select a).First();
string UserName = char.ToUpper(UserNameEntity.FirstName[0])
+ UserNameEntity.FirstName.Substring(1)
+ " "
+ char.ToUpper(UserNameEntity.LastName[0])
+ UserNameEntity.LastName.Substring(1);
return UserName;
This assumes that both properties are at least two characters in length.
You can also do this entirely in LINQ:
DBEntities Context = new DBEntities ();
IEnumerable<string> userNames = from a in Context.UserInformation
where a.UserId == UserId
let firstName = a.FirstName
let lastName = a.LastName
select (char.ToUpper(firstName[0])
+ firstName.Substring(1)
+ " "
+ char.ToUpper(lastName[0])
+ lastName.Substring(1));
return displayNames.First();
Obviously, using String.Format instead of concatenation may or may not improve readability.
The String class does not include a method that converts a string to title case. The ToTitleCase method resides in the TextInfo class, which is a member of the System.Globalization namespace. Unlike the ToUpper and ToLower methods of the String class, the ToTitleCase method is not a static method and requires an instance of the class.
CultureInfo cultureInfo = Thread.CurrentThread.CurrentCulture;
TextInfo textInfo = cultureInfo.TextInfo;
DBEntities Context = new DBEntities ();
var UserNameEntity = (from a in Context.UserInformation
where a.UserId == UserId
select a).First();
string UserName = textInfo.ToTitleCase(UserNameEntity.FirstName) + " " +
textInfo.ToTitleCase(UserNameEntity.LastName);
return UserName;
Check this for detailed information:
How to convert strings to lower, upper, or title (proper) case by using Visual C#
Currently I can send email successfully through WebDAV with C#, but there is a shortage in my App that I have hard-code the Exchange Server of my outlook, so it might only works for me, if it were moved to another PC and use another outlook account, it might not work because the Exchange Server for this outlook account might not the same as mine(that's beacuse our company for different email account might assign different Exchange server), so my question is that how can I get the Exchange Server for the current Email accout dynamically. In fact I can get this Exchange Server from the outlook client when I clicked the menu item to add a new Outlook Account, but dose there exist any API for me to get this Exchange Server programmatically such as with C#?
In fact I use the following code to send Email:
using System;
using System.Net;
using System.IO;
namespace WebDavNET
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
try
{
// TODO: Replace with the name of the computer that is running Exchange 2000.
string strServer = "ExchServe";
// TODO: Replace with the sender's alias.
string strSenderAlias = "sender";
// TODO: Replace with the sender's e-mail address.
string strFrom = "sender#example.com";
// TODO: Replace with the recipient's e-mail address.
string strTo = "recipient#example.com";
string strSubject = "Send Using HttpWebRequest";
string strBody = "Hello World";
string sUri;
sUri = "http://" + strServer + "/Exchange/" + strSenderAlias;
sUri = sUri + "/%23%23DavMailSubmissionURI%23%23/";
System.Uri myUri = new System.Uri(sUri);
HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(myUri);
string sQuery;
DateTime mySentTime = new DateTime();
sQuery = "From: " + strFrom + "\n" +
"To: " + strTo + "\n" +
"Subject: " + strSubject + "\n" +
"Date: " + DateTime.Now.ToString() + "\n" +
"X-Mailer: My DAV mailer" + "\n" +
"MIME-Version: 1.0" + "\n" +
"Content-Type: text/plain;" + "\n" +
"Charset = \"iso-8859-1\"" + "\n" +
"Content-Transfer-Encoding: 7bit" + "\n" + "\n" +
strBody;
// Set the credentials.
// TODO: Replace with the appropriate user credential.
NetworkCredential myCred = new NetworkCredential(#"DomainName\User", "Password");
CredentialCache myCredentialCache = new CredentialCache();
myCredentialCache.Add(myUri, "Basic", myCred);
HttpWRequest.Credentials = myCredentialCache;
// Set the headers.
HttpWRequest.Headers.Set("Translate", "f");
HttpWRequest.ContentType = "message/rfc822";
HttpWRequest.ContentLength = sQuery.Length;
//Set the request timeout to 5 minutes.
HttpWRequest.Timeout = 300000;
// Set the request method.
HttpWRequest.Method = "PUT";
// Store the data in a byte array.
byte[] ByteQuery = System.Text.Encoding.ASCII.GetBytes(sQuery);
HttpWRequest.ContentLength = ByteQuery.Length;
Stream QueryStream = HttpWRequest.GetRequestStream();
// write the data to be posted to the Request Stream
QueryStream.Write(ByteQuery,0,ByteQuery.Length);
QueryStream.Close();
// Send the request and get the response.
HttpWebResponse HttpWResponse = (HttpWebResponse)HttpWRequest.GetResponse();
// Get the Status code.
int iStatCode = (int)HttpWResponse.StatusCode;
string sStatus = iStatCode.ToString();
Console.WriteLine("Status Code: {0}", sStatus);
// Get the request headers.
string sReqHeaders = HttpWRequest.Headers.ToString();
Console.WriteLine(sReqHeaders);
// Read the response stream.
Stream strm = HttpWResponse.GetResponseStream();
StreamReader sr = new StreamReader(strm);
string sText = sr.ReadToEnd();
Console.WriteLine("Response: {0}", sText);
// Close the stream.
strm.Close();
// Clean up.
myCred = null;
myCredentialCache = null;
HttpWRequest = null;
HttpWResponse = null;
QueryStream = null;
strm = null;
sr = null;
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
}
As you can see in the code there is a variable named "strServer", In my App I just hard-code my Exchange Server for this variable, so my question is that dose there exist any API for me to get the Exchange Server dynamically for the specific outlook account?
Thanks!
You can use EWS(exchange Web Services) too. here is the link
You can use XML creator for creating items or requests required for operations in the link. Just go through the operations given on the link.