Skip to content

Instantly share code, notes, and snippets.

@emoacht
Last active August 29, 2015 14:23
Check if an OneDrive file is available in local PC.
using System;
using System.IO;
using System.Linq;
private class OneDriveFile
{
public static void CheckFileIsAvailable(string filePath)
{
var fileAttribute = File.GetAttributes(filePath);
Console.WriteLine("Attributes: {0}", fileAttribute);
var isAvailable = !fileAttribute.HasFlag(FileAttributes.Offline);
Console.WriteLine("Available: {0}", isAvailable);
try
{
new FileStream(filePath, FileMode.Open, FileAccess.Read).Close();
Console.WriteLine("CAN read.");
}
catch (IOException)
{
Console.WriteLine("CANNOT read.");
}
}
public void CheckFiles()
{
var folderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "SkyDrive", "Reference");
CheckFileIsAvailable(Path.Combine(folderPath, "容量計算.xlsx"));
// Attributes: Archive
// Available: True
// CAN read.
CheckFileIsAvailable(Path.Combine(folderPath, "暗号技術.pdf"));
// Attributes: Hidden, System, Archive, SparseFile, ReparsePoint, Offline
// Available: False
// CANNOT read.
Console.ReadLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment