|
just like we enter a १० in text-box,output as 10
|
|
|
|
|
Exactly how you do it depends on the culture in use on your computer. You need to use a Marathi culture for your inputs, and an English one for outputs. If your user culture is set to accept Marathi, then it's just decimal.TryParse . Otherwise specify the cultures:
string input = "12,12,12,123.45";
string output = "Not recognised as a number";
decimal d;
CultureInfo ciMarathi = CultureInfo.CreateSpecificCulture("mr-IN");
CultureInfo ciEnglishUK = CultureInfo.CreateSpecificCulture("en-GB");
if (decimal.TryParse(input,NumberStyles.Any, ciMarathi, out d))
{
output = d.ToString("#,0.##", ciEnglishUK);
} If you also want to include Marthi Unicode digits such as "४५९", there is an extra step:
string input = "४५,४५९.४५९";
string output = "Not recognised as a number";
decimal d;
input = new string(input.Select(c => char.IsDigit(c) ? (char) (char.GetNumericValue(c) + '0') : c).ToArray());
CultureInfo ciMarathi = CultureInfo.CreateSpecificCulture("mr-IN");
CultureInfo ciEnglishUK = CultureInfo.CreateSpecificCulture("en-GB");
if (decimal.TryParse(input,NumberStyles.Any, ciMarathi, out d))
{
output = d.ToString("#,0.##", ciEnglishUK);
}
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
You're welcome!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
I've been working to adapt code by Matthew Proctor. My goal is to remove the prompt, selecting the specific account, and downloading .xls attachments from a specific folder(inbox-attachments).
The program enumerates the email accounts, user selection, enumerates the "inbox's" subfolders, and extracts the .xls files. If anyone can point me in the right direction to accomplish this, I would very much appreciate the help. *I'm sorry that this is so long, but I didn't want to leave anything out that may be relevant.
using System;
using System.Linq;
using System.IO;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookAttachmentExtractor
{
class Program
{
static string basePath = @"c:\temp\DownloadedEmails\";
static int totalfilesize = 0;
static void Main(string[] args)
{
EnumerateAccounts();
}
static void EnumerateFolders(Outlook.Folder folder)
{
Outlook.Folders childFolders = folder.Folders;
if (childFolders.Count > 0)
{
foreach (Outlook.Folder childFolder in childFolders)
{
if (childFolder.FolderPath.Contains(@"Inbox"))
{
Console.WriteLine(childFolder.FolderPath);
EnumerateFolders(childFolder);
}
}
}
Console.WriteLine("Looking for items in " + folder.FolderPath);
IterateMessages(folder);
}
static void IterateMessages(Outlook.Folder folder)
{
string[] extensionsArray = { ".xls" };
var fi = folder.Items;
if (fi != null)
{
try
{
foreach (Object item in fi)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
var attachments = mi.Attachments;
if (attachments.Count != 0)
{
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
for (int i = 1; i <= mi.Attachments.Count; i++)
{
var fn = mi.Attachments[i].FileName.ToLower();
if (extensionsArray.Any(fn.Contains))
{
if (!Directory.Exists(basePath))
{
Directory.CreateDirectory(basePath);
}
totalfilesize = totalfilesize + mi.Attachments[i].Size;
if (!File.Exists(basePath + @"\" + mi.Sender.Address + @"\" + mi.Attachments[i].FileName))
{
Console.WriteLine("Saving " + mi.Attachments[i].FileName);
mi.Attachments[i].SaveAsFile(basePath + @"\" + mi.Attachments[i].FileName);
}
else
{
Console.WriteLine("Already saved " + mi.Attachments[i].FileName);
}
}
}
}
}
}
catch (Exception e)
{
}
}
}
static string EnumerateAccountEmailAddress(Outlook.Account account)
{
try
{
if (string.IsNullOrEmpty(account.SmtpAddress) || string.IsNullOrEmpty(account.UserName))
{
Outlook.AddressEntry oAE = account.CurrentUser.AddressEntry as Outlook.AddressEntry;
if (oAE.Type == "EX")
{
Outlook.ExchangeUser oEU = oAE.GetExchangeUser() as Outlook.ExchangeUser;
return oEU.PrimarySmtpAddress;
}
else
{
return oAE.Address;
}
}
else
{
return account.SmtpAddress;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return "";
}
}
static void EnumerateAccounts()
{
Console.Clear();
Console.WriteLine("Outlook XLS Extractor");
Console.WriteLine("---------------------------------");
int id;
Outlook.Application Application = new Outlook.Application();
Outlook.Accounts accounts = Application.Session.Accounts;
string response = "";
while (true == true)
{
id = 1;
foreach (Outlook.Account account in accounts)
{
Console.WriteLine(id + ":" + EnumerateAccountEmailAddress(account));
id++;
}
Console.WriteLine("Q: Quit Application");
response = Console.ReadLine().ToUpper();
if (response == "Q")
{
Console.WriteLine("Quitting");
return;
}
if (response != "")
{
if (Int32.Parse(response.Trim()) >= 1 && Int32.Parse(response.Trim()) < id)
{
Console.WriteLine("Processing: " + accounts[Int32.Parse(response.Trim())].DisplayName);
Console.WriteLine("Processing: " + EnumerateAccountEmailAddress(accounts[Int32.Parse(response.Trim())]));
Outlook.Folder selectedFolder = Application.Session.DefaultStore.GetRootFolder() as Outlook.Folder;
selectedFolder = GetFolder(@"\\" + accounts[Int32.Parse(response.Trim())].DisplayName);
EnumerateFolders(selectedFolder);
Console.WriteLine("Finished Processing " + accounts[Int32.Parse(response.Trim())].DisplayName);
Console.WriteLine("");
}
else
{
Console.WriteLine("Invalid Account Selected");
}
}
}
}
static Outlook.Folder GetFolder(string folderPath)
{
Console.WriteLine("Looking for: " + folderPath);
Outlook.Folder folder;
string backslash = @"\";
try
{
if (folderPath.StartsWith(@"\\"))
{
folderPath = folderPath.Remove(0, 2);
}
String[] folders = folderPath.Split(backslash.ToCharArray());
Outlook.Application Application = new Outlook.Application();
folder = Application.Session.Folders[folders[0]] as Outlook.Folder;
if (folder != null)
{
for (int i = 1; i <= folders.GetUpperBound(0); i++)
{
Outlook.Folders subFolders = folder.Folders;
folder = subFolders[folders[i]] as Outlook.Folder;
if (folder == null)
{
return null;
}
}
}
return folder;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
return null;
}
}
}
}
|
|
|
|
|
If you got the code from an article, then there is a "Add a Comment or Question" button at the bottom of that article, which causes an email to be sent to the author. They are then alerted that you wish to speak to them.
Posting this here relies on them "dropping by" and realising it is for them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I followed your advice, but assumed that anyone with experience with this subject may be able to shed some light. Wasn't really sure how likely I would be to get a response as the article was initially published in 2015.
|
|
|
|
|
That's only two years ago! We have active member that have been here 6 times that long - I've been here for over 7 years, and I'm still plugging away...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
see this class code
public class ShipperFactory
{
private static TShip Create<TShip>()
where TShip : IShip,
new()
{
return new TShip();
}
public static readonly IDictionary<Shipper, Func<IShip>> Creators =
new Dictionary<Shipper, Func<IShip>>()
{
{ Shipper.UPS, () => Create<ShipperUPS>() },
{ Shipper.FedEx, () => Create<ShipperFedEx>() },
{ Shipper.Purolator, () => Create<ShipperPurolator>() }
};
public static IShip CreateInstance(Shipper enumModuleName)
{
return Creators[enumModuleName]();
}
}
specially the below code is not clear where
public static readonly IDictionary<Shipper, Func<IShip>> Creators =
new Dictionary<Shipper, Func<IShip>>()
{
{ Shipper.UPS, () => Create<ShipperUPS>() },
{ Shipper.FedEx, () => Create<ShipperFedEx>() },
{ Shipper.Purolator, () => Create<ShipperPurolator>() }
};
1) see this line whose meaning is not clea. what is the meaning of Func<iship> ?
new Dictionary<shipper, func<iship="">>()
Dictionary usage is not clear. help me to understand the code of Dictionary and as well as ShipperFactory class.
it is required to use both interface and abstract class ? is it not redundant here ?
here giving the full code which show how i am using ShipperFactory class
calling like this way
--------------------------
private void btnUPS_Click(object sender, EventArgs e)
{
ShipperFactory.CreateInstance(Shipper.UPS).Ship();
}
private void btnFedEx_Click(object sender, EventArgs e)
{
ShipperFactory.CreateInstance(Shipper.FedEx).Ship();
}
private void btnPurolator_Click(object sender, EventArgs e)
{
ShipperFactory.CreateInstance(Shipper.Purolator).Ship();
}
public enum Shipper
{
UPS,
FedEx,
Purolator
}
public interface IShip
{
void Ship();
}
public abstract class ShipperBase : IShip
{
public abstract void Ship();
}
public class ShipperUPS : ShipperBase
{
public override void Ship()
{
MessageBox.Show("UPS ship start");
}
}
public class ShipperFedEx : ShipperBase
{
public override void Ship()
{
MessageBox.Show("FedEX ship start");
}
}
public class ShipperPurolator : ShipperBase
{
public override void Ship()
{
MessageBox.Show("Purolator ship start");
}
}
public class ShipperFactory
{
private static TShip Create<TShip>()
where TShip : IShip,
new()
{
return new TShip();
}
public static readonly IDictionary<Shipper, Func<IShip>> Creators =
new Dictionary<Shipper, Func<IShip>>()
{
{ Shipper.UPS, () => Create<ShipperUPS>() },
{ Shipper.FedEx, () => Create<ShipperFedEx>() },
{ Shipper.Purolator, () => Create<ShipperPurolator>() }
};
public static IShip CreateInstance(Shipper enumModuleName)
{
return Creators[enumModuleName]();
}
}
looking for help. thanks
tbhattacharjee
|
|
|
|
|
The dictionary contains a "key" for each carrier and a "function" (value) that is used to create an instance of that carrier.
Over-engineered and pointless indirection (IMO).
(A "carrier" class and a "carrier id / ident" would be simpler).
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
DNFTHV *
* Do not feed the Help Vampire
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
It's actually passive aggression
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
Some of these don't deserve "passive" - they just don't want to think for themselves...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Tridip Bhattacharjee wrote: looking for help Try asking the person who wrote the code.
|
|
|
|
|
i want to create a dynamic report ( ADD columns at run time ) with ASP.NET MVC 5
i tired for this , but there is no result for now
could you help me, please ???
|
|
|
|
|
Show us what you tried, and we would help make it work.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
He knew someone would advise if you can get in a desktop application username and password from the form to the current web page, which I have just entered? If yes, how? Thanks for any reply
Thanks.
Lubos
|
|
|
|
|
Your "question" makes no sense at all.
If you're asking how to grab the username and password from a Windows Forms app in javascript code in a web page, you can't.
|
|
|
|
|
Thank you Dave.
The page is opened. I just write username and password to to this page or to login form on page. I want to get this data to string in my desktop application. It is possible?
Best regards.
Thanks.
Lubos
|
|
|
|
|
These are the things that I have just written.
Thanks.
Lubos
|
|
|
|
|
The last two words. They must to be anywhere in my computer.
Thanks.
Lubos
|
|
|
|
|
Why do you think they must be somewhere?
The username is, probably, because it's a string and doesn't need any protection.
The password? Maybe, maybe not - it depends on the person who wrote the browser and how security aware they are.
But the real problem is: where? Almost certainly not in the same place for all browsers, pretty certainly not in the same place in memory if pages are opened in a different order. And they definitely won't be tagged as "This is the username" or "This is the password" to make them easy to find, because the browser doesn't know - or care - what the data is, though it may store username / password combos when it spots them (that storage is encrypted however, so you won't get it from there.
Basically, if you want to access this kind of stuff, the chances are it going to be:
1) Difficult.
2) Probably malicious.
And there's the rub: We do not condone, support, or assist in the production of malicious code in any way, form, or manner. This is a professional site for professional developers, and there is no good reason for password capture. As far as I can see, you are on your own with this one.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I have a feeling that we do not understand each other. I do not want to download passwords that have been saved. I just want to programmatically save to my database username and password that I just wrote that I did not have to write again. I write two words and I want to save them to the database. I do not want to write it twice. That is all.
Thanks.
Lubos
|
|
|
|
|
Then do it the other way around: store them in your DB and get your app to write them to the browser. That way, you aren't trying to do anything that could be seen as malicious (and is a damn sight easier as well).
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|