本文整理汇总了C#中System.IO.FileType.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FileType.ToString方法的具体用法?C# FileType.ToString怎么用?C# FileType.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileType
的用法示例。
在下文中一共展示了FileType.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeSerialize_SSCTechActivity
public static SSCTechActivity DeSerialize_SSCTechActivity(FileType fileType, int surveyRowID)
{
//Stream stream = File.Open(String.Format("{0}{1}{2}.{3}", FilePathType.SerData.DirPath(), AppNEnvConfig.GetFileSeperator, surveyRowID, fileType.ToString()), FileMode.Open);
Stream stream = File.Open(String.Format("{0}{1}{2}.{3}", AppNEnvConfig.TechSerData, AppNEnvConfig.GetFileSeperator, surveyRowID, fileType.ToString()), FileMode.Open);
BinaryFormatter bformatter = new BinaryFormatter();
var result = (SSCTechActivity)bformatter.Deserialize(stream);
stream.Close();
return result;
}
示例2: UrlToPdf
private string UrlToPdf(string url, FileType returnType)
{
var path = string.Format(@"{0}\lib\phantomjs-custom.exe", ApplicationDirectory);
if (string.IsNullOrEmpty(path) || !File.Exists(path))
{
throw new FileNotFoundException("Could not find PhantomJS executable.");
}
var dir = Path.GetDirectoryName(path);
if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
{
throw new FileNotFoundException("Could not determin PhantomJS base directory.");
}
var fileName = Path.GetFileName(path);
var savePath = string.Format(@"{0}{1}.{2}", Path.GetTempPath(), Guid.NewGuid(), returnType.ToString().ToLower());
// If is a local file, we need to adapt the path a bit
if (File.Exists(url))
{
url = string.Format("file:///{0}", Uri.EscapeDataString(url).Replace("%3A", ":").Replace("%5C", "/"));
}
var arguments = string.Format(@"--config=config.json scripts/run.js {0} {1}", url, savePath);
using (var process = new Process())
{
process.EnableRaisingEvents = true;
process.ErrorDataReceived += (sender, e) =>
{
throw new Exception("process.ErrorDataReceived");
};
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.ErrorDialog = true;
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments;
process.StartInfo.WorkingDirectory = dir;
process.Start();
process.WaitForExit(10000);
}
return savePath;
}
示例3: GetFileTypeExtension
public static string GetFileTypeExtension(FileType fileType)
{
switch (fileType)
{
case FileType.MP4:
return ".mp4";
case FileType.WMV:
return "wmv";
case FileType.XML:
return "xml";
case FileType.Unknown:
return null;
default:
throw new ApplicationException("Unexpected FileType enum value: " + fileType.ToString());
}
}
示例4: UploadFile
/// <summary>
/// New Upload File
/// </summary>
/// <param name="ID">Upload ID</param>
/// <param name="FileID">File ID</param>
/// <param name="Name">File Name</param>
/// <param name="FileType">File Type</param>
/// <param name="Client">TcpClient.</param>
public UploadFile(int ID, int FileID, string Name, FileType FileType, TcpClient Client)
{
this.ID = ID;
this.FileID = FileID;
this.Name = Name;
this.Type = FileType.ToString();
this.Client = Client;
if (FileType == FileType.CrashLog)
{
Stream = new FileStream(Core.Setting.ApplicationDirectory + "\\CrashLogs\\" + Name, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
Stream.Seek(0, SeekOrigin.Begin);
}
else if (FileType == FileType.Logger)
{
Stream = new FileStream(Core.Setting.ApplicationDirectory + "\\Logger\\" + Name, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
Stream.Seek(0, SeekOrigin.Begin);
}
Core.RCONPlayer.SentToPlayer(new Package(Package.PackageTypes.BeginCreateFile, new List<string> { FileID.ToString(), Name, Stream.Length.ToString() }, Client));
}
示例5: Serialize_SSCTechActivity
public static void Serialize_SSCTechActivity(SSCTechActivity result, FileType fileType)
{
//if (!Directory.Exists(FilePathType.SerData.DirPath()))
//{
// Directory.CreateDirectory(FilePathType.SerData.DirPath());
//}
//Stream stream = File.Open(String.Format("{0}{1}{2}.{3}", FilePathType.SerData.DirPath(), AppNEnvConfig.GetFileSeperator, result.SurveyRowID, fileType.ToString()), FileMode.Create);
//BinaryFormatter bformatter = new BinaryFormatter();
//bformatter.Serialize(stream, result);
//stream.Close();
if (!Directory.Exists(AppNEnvConfig.TechSerData))
{
Directory.CreateDirectory(AppNEnvConfig.TechSerData);
}
Stream stream = File.Open(String.Format("{0}{1}{2}.{3}", AppNEnvConfig.TechSerData, AppNEnvConfig.GetFileSeperator, result.SurveyRowID, fileType.ToString()), FileMode.Create);
BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, result);
stream.Close();
}
示例6: InitDirectory
/// <summary> 初始化类型文件夹 </summary>
/// <param name="type"></param>
private void InitDirectory(FileType type)
{
var path = Path.Combine(Contains.BaseDirectory, type.ToString().ToLower());
if (!Directory.Exists(path))
{
//初始化类型文件
path = Path.Combine(path, GenerateFirstDirectory(), Util.GenerateFileName());
_directoryCache[type] = path;
_fileCountCache[type] = 0;
return;
}
var parent = new DirectoryInfo(path);
var dir = parent.GetDirectories().OrderByDescending(t => t.LastWriteTime).FirstOrDefault();
//判断二级目录
if (dir == null || dir.GetDirectories().Length >= Contains.MaxFileCount)
{
var count = 1;
if (dir != null)
{
var search = string.Format("d{0}*", Convert.ToString(DateTime.Now.Year, 16));
count = parent.GetDirectories(search).Length + 1;
}
_directoryCache[type] = Path.Combine(path, GenerateFirstDirectory(count), Util.GenerateFileName());
_fileCountCache[type] = 0;
return;
}
path = dir.FullName;
dir = dir.GetDirectories().OrderByDescending(t => t.LastWriteTime).FirstOrDefault();
if (dir == null || dir.GetFiles().Length >= Contains.MaxFileCount)
{
_directoryCache[type] = Path.Combine(path, Util.GenerateFileName());
_fileCountCache[type] = 0;
return;
}
_directoryCache[type] = dir.FullName;
_fileCountCache[type] = dir.GetFiles().Length;
}
示例7: PrepareFile
/// <summary>подготовим файлы карт</summary>
private string PrepareFile(BusinessGraphicsResourceInfo info, FileType fType)
{
//достанем временной индентивикатор для карт, по нему будем ориентироваться новый файл или нет
ResourceFileProperty file = info.ResourceFileList.FirstOrDefault(f => f.Id.Equals(FileType.mapResource.ToString()));
//если файла карты нет, значит БГ без карты, возьмем тогда сам xml
if (file == null)
file = info.ResourceFileList.FirstOrDefault(f => f.Id.Equals(FileType.xmlResource.ToString()));
long dtFile = file.ModifiedUtc;
//информация об оригинальном файле
ResourceFileProperty oldMapFileName = info.ResourceFileList.FirstOrDefault(f => f.Id.Equals(fType.ToString()));
//информация о файле который приехал с сервера в качестве ресурса
string resFileName = GetFileByType(info, fType);
if (string.IsNullOrEmpty(resFileName) || !File.Exists(resFileName)) return string.Empty;
//имя файла как он должен называться
string newFileName = Path.Combine(
Path.GetDirectoryName(resFileName),
Path.GetFileNameWithoutExtension(oldMapFileName.ResourceFileName) +
dtFile.ToString() + "." + GetFileExtension(fType));
if (!File.Exists(newFileName))
{
File.Copy(resFileName, newFileName);
}
return newFileName;
}
示例8: write_Bmp_To_Txt_Batch
/// <summary>
/// Write the bmp images into number format to judge the threshold.
/// </summary>
/// <param name="filepath"></param>
/// <param name="savepath"></param>
/// <param name="filetype"></param>
public static void write_Bmp_To_Txt_Batch(string filepath, string savepath, FileType filetype)
{
try
{
if (filetype != FileType.bmp && filetype != FileType.jpg)
{
throw new Exception("The file type is not image.");
}
string inpath = "";
string outpath = "";
for (int i = 0; i < (1 << 10); i++)
{
inpath = filepath + "0(" + i.ToString() + ")." + filetype.ToString();
outpath = savepath + "0(" + i.ToString() + ")." + FileType.txt.ToString();
if (!File.Exists(inpath)) { break; }
IO.write_Bmp_To_Avg_Number(inpath, outpath);
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
示例9: write_Bmp_To_Bmp_Using_Threshold
/// <summary>
/// Using Threshold to process image and write them into certain position.
/// </summary>
/// <param name="filepath"></param>
/// <param name="savepath"></param>
/// <param name="filetype"></param>
public static void write_Bmp_To_Bmp_Using_Threshold(string filepath, string savepath, FileType filetype)
{
int i = 0;
int w = 0, h = 0;
string inpath = "";
string outpath = "";
Bitmap bitmap = null;
try
{
if (filetype != FileType.bmp && filetype != FileType.jpg)
{
throw new Exception("The file type is not image.");
}
for (i = 0; i < (1 << 10); i++)
{
inpath = filepath + "0(" + i.ToString() + ")." + filetype.ToString();
outpath = savepath + "0(" + i.ToString() + ")." + FileType.bmp.ToString();
if (!File.Exists(inpath)) { break; }
bitmap = Operations.Convert_Jpg2Bmp(inpath);
w = bitmap.Width;
h = bitmap.Height;
// Zoom out the image by certain ratio
bitmap = Scaling.Image_Zoom_Out(Config.Image_Scaling_Ratio, bitmap);
// Zoom in the image to the original size
bitmap = Scaling.Image_Zoom_In(w, h, bitmap);
// Do uniformization operation
Operations.Uniformization_Bmp(bitmap);
// Remove black edges
Operations.Generate_White_Edges(bitmap);
#if Remove_Suspending_Points
// Remove suspending points
Operations.Remove_Suspending_Points(bitmap);
#endif
#if Remove_Thin_Vertical_Line
// Remove thin vertical lines
Operations.Remove_Thin_Vertical_Lines(bitmap);
#endif
bitmap.Save(outpath, ImageFormat.Bmp);
}
}
catch (Exception e)
{
throw new Exception(e.Message);
}
}
示例10: GetExtension
// ============================================
// PUBLIC Methods
// ============================================
public static string[] GetExtension(FileType type)
{
int position = (int) Enum.Parse(typeof(FileType), type.ToString());
return(Extensions[position]);
}
示例11: MakePattern
// ============================================
// PRIVATE Methods
// ============================================
private static string MakePattern(FileType type)
{
return(MakePattern(type.ToString()));
}
示例12: CreateZipActionContentItem
private ContentItem CreateZipActionContentItem(string password, FileType fileType, string filePath, string contentId, string parentId)
{
PolicySet[] policySets;
switch (fileType)
{
case FileType.Email:
case FileType.ZIP:
case FileType.OutlookMessageFile:
policySets = CreateContainerPolicySets();
break;
default:
policySets = CreateDocumentPolicySets(password);
break;
}
CustomProperty[] properties = CreateProperties(filePath, contentId);
return new ContentItem
{
ContentType = fileType.ToString(),
Name = filePath,
DisplayName = Path.GetFileName(filePath),
Id = contentId,
ParentId = parentId,
PolicySets = policySets,
Properties = properties
};
}
示例13: GetExtension
private string GetExtension(FileType type)
{
switch (type)
{
case FileType.GMAD:
return ".gma";
case FileType.LZMA:
return ".7z";
default:
return "." + type.ToString().ToLower();
}
}
示例14: GetData
private FileContentResult GetData(FileType fileType)
{
FileContentResult fr = null;
ReadDataFromRouteData();
string folderPrefix = string.Empty;
switch (fileType.ToString())
{
case "js":
folderPrefix = "Scripts";
break;
case "css":
folderPrefix = "Styles";
break;
case "image":
folderPrefix = "Images";
break;
}
try
{
string fileFullPath = Path.Combine(_adminManager.DataPath, "knowledgebase", "portalConfiguration", clientId.ToString(), portalId.ToString(), folderPrefix, fileName);
System.IO.MemoryStream s = _adminManager.ReadFileStream(fileFullPath);
byte[] bts = new byte[s.Length];
s.Read(bts, 0, bts.Length);
string contentType = Mime.FromExtension(Path.GetExtension(fileFullPath));
fr = new FileContentResult(bts, contentType);
}
catch (IOException ex)
{
KBCustomException kbCustExp = KBCustomException.ProcessException(ex, KBOp.LoadContent, KBErrorHandler.GetMethodName(), GeneralResources.IOError,
new KBExceptionData("fileType", fileType.ToString()), new KBExceptionData("clientId", clientId), new KBExceptionData("portalId", portalId),
new KBExceptionData("folderPrefix", folderPrefix), new KBExceptionData("fileName", fileName));
throw kbCustExp;
}
catch (Exception ex)
{
KBCustomException kbCustExp = KBCustomException.ProcessException(ex, KBOp.LoadContent, KBErrorHandler.GetMethodName(), GeneralResources.GeneralError,
new KBExceptionData("fileType", fileType.ToString()), new KBExceptionData("clientId", clientId), new KBExceptionData("portalId", portalId),
new KBExceptionData("folderPrefix", folderPrefix), new KBExceptionData("fileName", fileName));
throw kbCustExp;
}
return fr;
}
示例15: CheckAndSetDefault
/// <summary>
/// return true if the operation succeeded.
/// otherwise, return false
/// </summary>
internal string CheckAndSetDefault()
{
// we validate the options here and also set default
// if we can
// Rule #1: One and only one action at a time
// i.e. Can't parse and generate at the same time
// Must do one of them
if ((ToParse && ToGenerate) ||
(!ToParse && !ToGenerate))
return StringLoader.Get("MustChooseOneAction");
// Rule #2: Must have an input
if (string.IsNullOrEmpty(Input))
{
return StringLoader.Get("InputFileRequired");
}
else
{
if (!File.Exists(Input))
{
return StringLoader.Get("FileNotFound", Input);
}
string extension = Path.GetExtension(Input);
// Get the input file type.
if (string.Compare(extension, "." + FileType.BAML.ToString(), true, CultureInfo.InvariantCulture) == 0)
{
InputType = FileType.BAML;
}
else if (string.Compare(extension, "." + FileType.RESOURCES.ToString(), true, CultureInfo.InvariantCulture) == 0)
{
InputType = FileType.RESOURCES;
}
else if (string.Compare(extension, "." + FileType.DLL.ToString(), true, CultureInfo.InvariantCulture) == 0)
{
InputType = FileType.DLL;
}
else if (string.Compare(extension, "." + FileType.EXE.ToString(), true, CultureInfo.InvariantCulture) == 0)
{
InputType = FileType.EXE;
}
else
{
return StringLoader.Get("FileTypeNotSupported", extension);
}
}
if (ToGenerate)
{
// Rule #3: before generation, we must have Culture string
if (CultureInfo == null && InputType != FileType.BAML)
{
// if we are not generating baml,
return StringLoader.Get("CultureNameNeeded", InputType.ToString());
}
// Rule #4: before generation, we must have translation file
if (string.IsNullOrEmpty(Translations))
{
return StringLoader.Get("TranslationNeeded");
}
else
{
string extension = Path.GetExtension(Translations);
if (!File.Exists(Translations))
{
return StringLoader.Get("TranslationNotFound", Translations);
}
else
{
if (string.Compare(extension, "." + FileType.CSV.ToString(), true, CultureInfo.InvariantCulture) == 0)
{
TranslationFileType = FileType.CSV;
}
else
{
TranslationFileType = FileType.TXT;
}
}
}
}
// Rule #5: If the output file name is empty, we act accordingly
if (string.IsNullOrEmpty(Output))
{
// Rule #5.1: If it is parse, we default to [input file name].csv
if (ToParse)
{
string fileName = Path.GetFileNameWithoutExtension(Input);
Output = fileName + "." + FileType.CSV.ToString();
TranslationFileType = FileType.CSV;
}
//.........这里部分代码省略.........