Показать сообщение отдельно
Старый 12.02.2015, 22:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,644 / 848 (80) +++++++
Регистрация: 28.10.2006
palleagermark: Build a valid file name
Источник: http://www.agermark.com/2015/02/buil...file-name.html
==============

I could find anything in AX building a true valid file name. That is only the name of the file itself, not the path.

So I came up with this:
public static Filename buildValidFilename(str _filename)
{
#xppTexts
#define.LeftSquareBracket('[')
#define.RightSquareBracket(']')

Filename validFilename;
str invalidFileNameChars;

new InteropPermission(InteropKind::ClrInterop).assert();

// Remove the characters that .NET defines as invalid
invalidFileNameChars = new System.String(System.IO.Path::GetInvalidFileNameChars());
validFilename = System.Text.RegularExpressions.Regex::Replace(_filename, #LeftSquareBracket + invalidFileNameChars + #RightSquareBracket, #emptyString);

// Remove the characters that .NET doesn't remove
invalidFileNameChars = @'"\\/:*?\|' + "'";
validFilename = System.Text.RegularExpressions.Regex::Replace(validFilename, #LeftSquareBracket + invalidFileNameChars + #RightSquareBracket, #emptyString);

CodeAccessPermission::revertAssert();

return validFilename;
}

Источник: http://www.agermark.com/2015/02/buil...file-name.html
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.