本文整理汇总了C#中File.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# File.Exists方法的具体用法?C# File.Exists怎么用?C# File.Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类File
的用法示例。
在下文中一共展示了File.Exists方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAndSaveLocal
public void CreateAndSaveLocal()
{
IKp2aApp app = new TestKp2aApp();
IOConnectionInfo ioc = new IOConnectionInfo {Path = DefaultFilename};
File outputDir = new File(DefaultDirectory);
outputDir.Mkdirs();
File targetFile = new File(ioc.Path);
if (targetFile.Exists())
targetFile.Delete();
bool createSuccesful = false;
//create the task:
CreateDb createDb = new CreateDb(app, Application.Context, ioc, new ActionOnFinish((success, message) =>
{ createSuccesful = success;
if (!success)
Android.Util.Log.Debug("KP2A_Test", message);
}), false);
//run it:
createDb.Run();
//check expectations:
Assert.IsTrue(createSuccesful);
Assert.IsNotNull(app.GetDb());
Assert.IsNotNull(app.GetDb().KpDatabase);
//the create task should create two groups:
Assert.AreEqual(2, app.GetDb().KpDatabase.RootGroup.Groups.Count());
//ensure the the database can be loaded from file:
PwDatabase loadedDb = new PwDatabase();
loadedDb.Open(ioc, new CompositeKey(), null, new KdbxDatabaseFormat(KdbxFormat.Default));
//Check whether the databases are equal
AssertDatabasesAreEqual(loadedDb, app.GetDb().KpDatabase);
}
示例2: dir_exists
public bool dir_exists(string dir_path)
{
bool ret = false;
File dir = new File(dir_path);
if(dir.Exists()&& dir.IsDirectory)
ret = true;
return ret;
}
示例3: CreateDirectoryForPictures
private void CreateDirectoryForPictures()
{
_dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
if (_dir.Exists())
{
_dir.Mkdirs();
}
}
示例4: WriteToFile
public void WriteToFile(string fileName, string text)
{
try
{
File file = new File(context.FilesDir.AbsolutePath, fileName);
if (file.Exists())
{
file.Delete();
}
var outputStreamWriter = new OutputStreamWriter(context.OpenFileOutput(fileName, FileCreationMode.Private));
outputStreamWriter.Write(text);
outputStreamWriter.Close();
}
catch (IOException e)
{
Log.Debug("Exception", "File write failed: " + e.ToString());
}
}
示例5: OnCreate
protected override void OnCreate(Bundle bundle)
{
System.Console.WriteLine("PictureConfirmActivity start");
base.OnCreate (bundle);
RequestWindowFeature(WindowFeatures.NoTitle);
Window.AddFlags (WindowManagerFlags.Fullscreen);
SetContentView (Resource.Layout.PictureConfirmLayout);
filepath = Intent.GetStringExtra ("filepath");
latitude = Intent.GetDoubleExtra ("latitude",0);
longitude = Intent.GetDoubleExtra ("longitude",0);
File imageFile = new File (filepath);
if (imageFile.Exists ()) {
Bitmap bm = BitmapFactory.DecodeFile (filepath);
ImageView newPicture = (ImageView)FindViewById (Resource.Id.pictureConfirmImage);
newPicture.SetImageBitmap (bm);
}
var submitButton = (Button)FindViewById (Resource.Id.pictureConfirmSubmitButton);
submitButton.Click += (sender, e) => {
//get auth token
AccountManager am = AccountManager.Get (this);
Account[] accounts = am.GetAccountsByType("com.SnapAndGo.auth");
var accFut = AccountManager.Get (this).GetAuthToken (accounts [0], "com.SnapAndGo.auth", null, this, null, null);
Bundle authTokenBundle = (Bundle)accFut.GetResult(20,Java.Util.Concurrent.TimeUnit.Seconds);
String authToken = authTokenBundle.Get (AccountManager.KeyAuthtoken).ToString ();
new PostPictureTask(this, authToken, filepath, latitude, longitude).Execute("TASK");
};
var cancelButton = (Button)FindViewById (Resource.Id.pictureConfirmCancelButton);
cancelButton.Click += (sender, e) => {
StartActivity(typeof(CustomCameraActivity));
};
System.Console.WriteLine("PictureConfirmActivity End");
}
示例6: TakePictureAsync
public Task<CameraResult> TakePictureAsync()
{
Intent intent = new Intent(MediaStore.ActionImageCapture);
pictureDirectory = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "CameraAppDemo");
if (!pictureDirectory.Exists())
{
pictureDirectory.Mkdirs();
}
file = new File(pictureDirectory, String.Format("photo_{0}.jpg", Guid.NewGuid()));
intent.PutExtra(MediaStore.ExtraOutput, Uri.FromFile(file));
var activity = (Activity)Forms.Context;
activity.StartActivityForResult(intent, 0);
tcs = new TaskCompletionSource<CameraResult>();
return tcs.Task;
}
示例7: GetOutputMediaFile
/// <summary>
/// Gets a file where to store the picture.
/// </summary>
private static File GetOutputMediaFile()
{
var mediaStorageDir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "dot42 Simple Camera");
if (!mediaStorageDir.Exists())
{
if (!mediaStorageDir.Mkdirs())
{
Log.E("dot42 Simple Camera", "failed to create directory");
return null;
}
}
// Create a media file name
var timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").Format(new Date());
var mediaFile = new File(mediaStorageDir.Path + File.Separator + "IMG_" + timeStamp + ".jpg");
return mediaFile;
}
示例8: CreatePhotoDir
private void CreatePhotoDir()
{
try
{
_dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), _photoSubDir);
if (!_dir.Exists())
_dir.Mkdirs();
}
catch
{
_dir = null;
}
}
示例9: deleteDirectoryContent
private static void deleteDirectoryContent(string path)
{
try
{
var dir = new File (path);
if (dir.Exists() && dir.IsDirectory)
{
var children = dir.List();
for (int i = 0; i < children.Length; i++) {
new File(dir, children[i]).Delete();
}
}
}
catch (Exception ex)
{
Log.Error ("WIKITUDE_EXAMPLE", ex.ToString());
}
}
示例10: CheckForBinary
public bool CheckForBinary(string filename)
{
bool result = false;
foreach (var path in pathsArray)
{
var completePath = path + filename;
File f = new File(completePath);
bool fileExists = f.Exists();
if (fileExists)
{
logBuilder.AppendFormat("{0} binary detected!{1}", completePath, LINE);
result = true;
}
}
return result;
}
示例11: GetFileForDocId
/**
* Translate your custom URI scheme into a File object.
*
* @param docId the document ID representing the desired file
* @return a File represented by the given document ID
*/
File GetFileForDocId (String docId)
{
File target = mBaseDir;
if (docId == ROOT) {
return target;
}
int splitIndex = docId.IndexOf (':', 1);
if (splitIndex < 0) {
throw new FileNotFoundException ("Missing root for " + docId);
} else {
string path = docId.Substring (splitIndex + 1);
target = new File (target, path);
if (!target.Exists ()) {
throw new FileNotFoundException ("Missing file for " + docId + " at " + target);
}
return target;
}
}
示例12: pullNote
// pull note used for revert
protected override void pullNote(string guid)
{
// start loading local notes
TLog.v(TAG, "pulling remote note");
File path = new File(Tomdroid.NOTES_PATH);
if (!path.Exists())
path.Mkdir();
TLog.i(TAG, "Path {0} Exists: {1}", path, path.Exists());
// Check a second time, if not the most likely cause is the volume doesn't exist
if(!path.Exists()) {
TLog.w(TAG, "Couldn't create {0}", path);
SendMessage(NO_SD_CARD);
return;
}
path = new File(Tomdroid.NOTES_PATH + guid + ".note");
SyncInThread(new Worker(path, false, false));
}
示例13: photo_Touch
private void photo_Touch(object sender, View.TouchEventArgs e)
{
if (context.cameraBusy)
return;
context.cameraBusy = true;
_dir = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryPictures), "Pictures");
if (!_dir.Exists())
{
if (!_dir.Mkdirs())
throw new InvalidOperationException("Unable to create temporary directory");
}
var intent = new Intent(MediaStore.ActionImageCapture);
imageFile = new File(_dir, string.Format("image_{0}.jpg", Guid.NewGuid()));
intent.PutExtra(MediaStore.ExtraOutput, Android.Net.Uri.FromFile(imageFile));
context.StartActivityForResult(intent, EditItemMainActivity.GetImageIntent);
/* var intent = new Intent();
intent.SetType("image/*");
intent.SetAction(Intent.ActionGetContent);
context.StartActivityForResult(Intent.CreateChooser(intent, "Выберите фото"), EditItemMainActivity.GetImageIntent);*/
}
示例14: treeElem_OnGetImage
/// <summary>
/// Method for obtaining image url for given tree node (category).
/// </summary>
/// <param name="node">Node (category)</param>
/// <returns>Image URL</returns>
protected string treeElem_OnGetImage(UniTreeNode node)
{
File f = new File();
DataRow dr = node.ItemData as DataRow;
string imgUrl = string.Empty;
try
{
if (dr != null)
{
// Get icon path
imgUrl = ValidationHelper.GetString(dr["CategoryIconPath"], "");
if (!String.IsNullOrEmpty(imgUrl))
{
if (CMS.IO.Path.IsPathRooted(imgUrl))
{
imgUrl = GetImagePath("CMSModules/CMS_Settings/Categories/list.png");
}
else if (!ValidationHelper.IsURL(imgUrl))
{
imgUrl = GetImagePath(imgUrl);
}
else
{
return imgUrl;
}
}
else
{
// If requested icon not found try to get icon as previous version did
string categoryName = ValidationHelper.GetString(dr["CategoryName"], "");
imgUrl = GetImagePath("CMSModules/CMS_Settings/Categories/" + categoryName.Replace(".", "_") + "/list.png");
}
}
// Get default icon if requested icon not found
if (!f.Exists(Server.MapPath(imgUrl)))
{
imgUrl = GetImagePath("CMSModules/CMS_Settings/Categories/list.png");
}
}
catch
{
imgUrl = GetImagePath("CMSModules/CMS_Settings/Categories/list.png");
}
return URLHelper.ResolveUrl(imgUrl);
}
示例15: TakeAPicture
private void TakeAPicture(object sender, EventArgs eventArgs){
File imageStorageDir = new File(global::Android.OS.Environment.GetExternalStoragePublicDirectory( global::Android.OS.Environment.DirectoryPictures), "AndroidExampleFolder");
if (!imageStorageDir.Exists()) {
// Create AndroidExampleFolder at sdcard
imageStorageDir.Mkdir();
}
// Create camera captured image file path and name
File file = new File(imageStorageDir + File.Separator + "IMG_" + Utils.RandomString(10) + ".jpg");
mCapturedImageURI = Uri.FromFile(file);
// Camera capture image intent
Intent captureIntent = new Intent(global::Android.Provider.MediaStore.ActionImageCapture);
captureIntent.PutExtra(MediaStore.ExtraOutput, mCapturedImageURI);
StartActivityForResult(captureIntent, FILECHOOSER_RESULTCODE);
}