本文整理汇总了C#中File.Length方法的典型用法代码示例。如果您正苦于以下问题:C# File.Length方法的具体用法?C# File.Length怎么用?C# File.Length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.Length方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetImageSize
public static AccidentMediaViewModel GetImageSize(string fileName)
{
var options = new BitmapFactory.Options
{
InJustDecodeBounds = true
};
File file = new File(fileName);
long lengthMB = file.Length() / 1024;
BitmapFactory.DecodeFile(fileName, options);
int width = options.OutWidth;
int height = options.OutHeight;
string type = options.OutMimeType;
file.Dispose();
return new AccidentMediaViewModel
{
Height = height,
MimeType = type,
Filename = fileName,
SizeKb = lengthMB,
Width = width
};
}
示例2: IncludeFile
/**
* Add a representation of a file to a cursor.
*
* @param result the cursor to modify
* @param docId the document ID representing the desired file (may be null if given file)
* @param file the File object representing the desired file (may be null if given docID)
*/
void IncludeFile (MatrixCursor result, string docId, File file)
{
if (docId == null) {
docId = GetDocIdForFile (file);
} else {
file = GetFileForDocId (docId);
}
DocumentContractFlags flags = (DocumentContractFlags)0;
if (file.IsDirectory) {
// Request the folder to lay out as a grid rather than a list. This also allows a larger
// thumbnail to be displayed for each image.
// flags |= Document.FLAG_DIR_PREFERS_GRID;
// Add FLAG_DIR_SUPPORTS_CREATE if the file is a writable directory.
if (file.IsDirectory && file.CanWrite ()) {
flags |= DocumentContractFlags.DirSupportsCreate;
}
} else if (file.CanWrite ()) {
// If the file is writable set FLAG_SUPPORTS_WRITE and
// FLAG_SUPPORTS_DELETE
flags |= DocumentContractFlags.SupportsWrite;
flags |= DocumentContractFlags.SupportsDelete;
}
string displayName = file.Name;
string mimeType = GetTypeForFile (file);
if (mimeType.StartsWith ("image/")) {
// Allow the image to be represented by a thumbnail rather than an icon
flags |= DocumentContractFlags.SupportsThumbnail;
}
MatrixCursor.RowBuilder row = result.NewRow ();
row.Add (DocumentsContract.Document.ColumnDocumentId, docId);
row.Add (DocumentsContract.Document.ColumnDisplayName, displayName);
row.Add (DocumentsContract.Document.ColumnSize, file.Length ());
row.Add (DocumentsContract.Document.ColumnMimeType, mimeType);
row.Add (DocumentsContract.Document.ColumnLastModified, file.LastModified ());
row.Add (DocumentsContract.Document.ColumnFlags, (int)flags);
// Add a custom icon
row.Add (DocumentsContract.Document.ColumnIcon, Resource.Drawable.icon);
}