public async Task <ItemInformation[]> GetFilesList(string path) { try { ListFolderResult list = await client.Files.ListFolderAsync(path, recursive : false, includeMediaInfo : true); ItemInformation[] res = new ItemInformation[list.Entries.Count]; Metadata element; for (int i = 0; i < res.Length; i++) { element = list.Entries[i]; res[i] = new ItemInformation(); res[i].Name = element.Name; res[i].Fullpath = element.PathDisplay; if (element.IsFolder) { res[i].Type = ElementType.dir; } else { string[] temp = element.Name.Split('.'); res[i].Type = GetItemType(temp[temp.Length - 1]); res[i].Size = element.AsFile.Size; res[i].EditDate = element.AsFile.ServerModified; } } return(res); } catch (Exception e) { Console.WriteLine(e.Message); return(null); } }
public async Task <ItemInformation[]> ListOfSharedLinksAsync() { var list = await client.Sharing.ListSharedLinksAsync(null, null, false); ItemInformation[] res = new ItemInformation[list.Links.Count]; SharedLinkMetadata element; for (int i = 0; i < res.Length; i++) { element = list.Links[i]; res[i] = new ItemInformation(); res[i].Name = element.Name; res[i].Fullpath = element.PathLower; if (element.IsFolder) { res[i].Type = ElementType.dir; } else { string[] temp = element.Name.Split('.'); res[i].Type = GetItemType(temp[temp.Length - 1]); res[i].Size = element.AsFile.Size; res[i].EditDate = element.AsFile.ServerModified; } res[i].Share_url = element.Url; } return(res); }
public async Task <ItemInformation> UploadAsync(string path, Stream stream = null) { if (stream == null) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; if (dialog.ShowDialog() != DialogResult.OK) { return(null); } stream = dialog.OpenFile(); } FileMetadata metadata = await client.Files.UploadAsync( path, WriteMode.Overwrite.Instance, body : stream); ItemInformation result = new ItemInformation(); result.Name = metadata.Name; result.Fullpath = metadata.PathDisplay; if (metadata.IsFolder) { result.Type = ElementType.dir; } else { string[] temp = metadata.Name.Split('.'); result.Type = GetItemType(temp[temp.Length - 1]); result.Size = metadata.AsFile.Size; result.EditDate = metadata.AsFile.ServerModified; } return(result); }
public async Task <ItemInformation> ShareAsync(string path) { var metadata = await client.Sharing.CreateSharedLinkWithSettingsAsync(path); ItemInformation result = new ItemInformation(); result.Name = metadata.Name; result.Fullpath = metadata.PathLower; result.Share_url = metadata.Url; if (metadata.IsFolder) { result.Type = ElementType.dir; } else { string[] temp = metadata.Name.Split('.'); result.Type = GetItemType(temp[temp.Length - 1]); result.Size = metadata.AsFile.Size; result.EditDate = metadata.AsFile.ServerModified; } return(result); }
public async Task <ItemInformation> CreateDirectory(string path) { var metadata = await client.Files.CreateFolderAsync( path, autorename : true); ItemInformation result = new ItemInformation(); result.Name = metadata.Name; result.Fullpath = metadata.PathDisplay; if (metadata.IsFolder) { result.Type = ElementType.dir; } else { string[] temp = metadata.Name.Split('.'); result.Type = GetItemType(temp[temp.Length - 1]); result.Size = metadata.AsFile.Size; result.EditDate = metadata.AsFile.ServerModified; } return(result); }
public async Task <ItemInformation[]> SearchAsync(string path, string query, uint takeCount = 1000, bool includeContent = true) { SearchMode serachMode; if (includeContent) { serachMode = SearchMode.FilenameAndContent.Instance; } else { serachMode = SearchMode.Filename.Instance; } var list = await client.Files.SearchAsync(path, query, 0, takeCount, serachMode); ItemInformation[] res = new ItemInformation[list.Matches.Count]; Metadata element; for (int i = 0; i < res.Length; i++) { element = list.Matches[i].Metadata; res[i] = new ItemInformation(); res[i].Name = element.Name; res[i].Fullpath = element.PathLower; if (element.IsFolder) { res[i].Type = ElementType.dir; } else { string[] temp = element.Name.Split('.'); res[i].Type = GetItemType(temp[temp.Length - 1]); res[i].Size = element.AsFile.Size; res[i].EditDate = element.AsFile.ServerModified; } } return(res); }