user1095549
user1095549

Reputation: 1429

get the real file name from temp

I have a small project that functions to saves and deal with all new items that enter it in a folder.

My problem is that when items from Gmail are transferred to this folder the attachment name gets new extensions that are not recognized, and then cannot be located as they are not the original name.

For example it comes as AAA.PDF.GGG.ORT, when it is filed as AAA.PDF.

How can I get the real file name, without the added extensions?

Upvotes: 2

Views: 89

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460158

The original file name is always with only one extension Ex: AAA.PDF or DDD.JPEG

Then it is easy:

string fileName = System.IO.Path.GetFileName(fullName); // "AAA.PDF.GGG.ORT"
string[] fileNameToken = fileName.Split('.');
string originalFileName = string.Format("{0}.{1}", fileNameToken[0], fileNameToken[1]);

Upvotes: 2

gbro3n
gbro3n

Reputation: 6967

Presuming there's some pattern to the number of characters after the 'real' file extension, I would use a sub string function similar to convert the file name.

Upvotes: 0

Related Questions