void treeViewUsers_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { treeViewFiles.Nodes.Clear(); gbl_current_member_index = e.Node.Index; FolderListing rootFolderListing = Get_listing("/", txtToken.Text, gbl_TeamObject.members[gbl_current_member_index].profile.member_id); foreach (FolderContent fc in rootFolderListing.contents) { //strip the backslash for display in the tree string tmp = fc.path; string tmpWithoutSlash = tmp.Substring(1); TreeNode treeNode = new TreeNode(tmpWithoutSlash); //change icon for files/folders if (fc.is_dir == "false") { treeNode.ImageKey = "file"; treeNode.SelectedImageKey = "file"; } else { treeNode.ImageKey = "folder_closed"; } treeViewFiles.Nodes.Add(treeNode); } }
protected void treeViewFiles_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { Console.WriteLine("Node Clicked: " + e.Node.Index); if (e.Node.Parent != null) { Console.WriteLine("Node Clicked Parent: " + e.Node.Parent.Index); } else { Console.WriteLine("Node Clicked Parent: no parent"); } //dont re-do the call if the node is already populated if (e.Node.IsExpanded == false && e.Node.ImageKey != "file") { string tmpPath = "/" + e.Node.FullPath; string slashPath = tmpPath.Replace("\\", "/"); FolderListing subfolder = Get_listing(slashPath, txtToken.Text, gbl_TeamObject.members[gbl_current_member_index].profile.member_id); if (subfolder.contents != null && subfolder.contents.Count > 0) { //this prevents the duplicates showing up when clicking same folder again... RemoveChildNodes(e.Node); } foreach (FolderContent fc in subfolder.contents) { //strip the backslash and parent folder deets for display in the tree string tmp = fc.path; int originatingFolderLength = slashPath.Length + 1; string tmpWithoutSlash = tmp.Substring(originatingFolderLength); treeViewFiles.BeginUpdate(); TreeNode treeNode = new TreeNode(tmpWithoutSlash); //change icon for files/folders if (fc.is_dir == "false") { treeNode.ImageKey = "file"; treeNode.SelectedImageKey = "file"; } else { treeNode.ImageKey = "folder_closed"; } string fullpath = treeViewFiles.SelectedNode.FullPath.ToString(); e.Node.Nodes.Add(treeNode); treeViewFiles.EndUpdate(); e.Node.ExpandAll(); } } else { //second click user wants to collapse tree e.Node.Collapse(); } }
/// <summary> /// Obtiene los directorios contenidos en una carpeta de repositorio asincrónicamente /// </summary> /// <param name="directorio">Objeto que representa una carpeta</param> /// <param name="sesion">Objeto de sesión del repositorio</param /// /// <returns>Lista de documentos</returns> public static Task <IEnumerable <DocumentoRepositorio> > ExtraerDirectoriosAsync(this DocumentoRepositorio directorio, object sesion = null) { if (!directorio.Directorio) { throw new Exception("No es directorio"); } return(Task.Run <IEnumerable <DocumentoRepositorio> >(() => { if (directorio.Repositorio == Repositorio.Laserfiche) { FolderInfo directorioAsociado = (FolderInfo)directorio.DocumentoAsociado; var ens = new EntryListingSettings(); ens.EntryFilter = EntryTypeFilter.Folders; ens.AddColumn(SystemColumn.Name); ens.AddColumn(SystemColumn.Uuid); FolderListing listado = directorioAsociado.OpenFolderListing(ens); List <DocumentoRepositorio> documentoRepositorios = new List <DocumentoRepositorio>(); for (int registro = 1; registro <= listado.RowCount; registro++) { DocumentoRepositorio documentoRepositorio = new DocumentoRepositorio(); EntryInfo informacionEntrada = listado.GetEntryInfo(registro); documentoRepositorio.Directorio = informacionEntrada.EntryType == EntryType.Folder; DocumentInfo documentInfo = null; FolderInfo folderInfo = null; if (documentoRepositorio.Directorio) { folderInfo = Folder.GetFolderInfo(informacionEntrada.Id, (Session)sesion); documentoRepositorio.DocumentoAsociado = folderInfo; } else { documentInfo = Document.GetDocumentInfo(informacionEntrada.Id, (Session)sesion); documentoRepositorio.DocumentoAsociado = documentInfo; } documentoRepositorio.Repositorio = Repositorio.Laserfiche; documentoRepositorio.Nombre = documentoRepositorio.Directorio ? folderInfo.Name : documentInfo.Name; //documentoRepositorio.Plantilla = documentInfo.TemplateName; documentoRepositorio.Ruta = folderInfo.Path; documentoRepositorios.Add(documentoRepositorio); } return documentoRepositorios; } return new List <DocumentoRepositorio>(); })); }
public static IEnumerable <DocumentoRepositorio> RecuperarDocumentos(this DocumentoRepositorio directorio, Session sesion) { if (!directorio.Directorio) { throw new Exception("No es directorio"); } if (directorio.Repositorio == Repositorio.Laserfiche) { FolderInfo directorioAsociado = (FolderInfo)directorio.DocumentoAsociado; var ens = new EntryListingSettings(); ens.EntryFilter = EntryTypeFilter.Documents; ens.AddColumn(SystemColumn.Name); ens.AddColumn(SystemColumn.Uuid); FolderListing listado = directorioAsociado.OpenFolderListing(ens); List <DocumentoRepositorio> documentoRepositorios = new List <DocumentoRepositorio>(); DocumentoRepositorio documentoRepositorio = new DocumentoRepositorio(); for (int registro = 1; registro <= listado.RowCount; registro++) { EntryInfo informacionEntrada = listado.GetEntryInfo(registro); documentoRepositorio.Directorio = informacionEntrada.EntryType == EntryType.Folder; DocumentInfo documentInfo = null; FolderInfo folderInfo = null; if (documentoRepositorio.Directorio) { folderInfo = Folder.GetFolderInfo(informacionEntrada.Id, sesion); documentoRepositorio.DocumentoAsociado = folderInfo; } else { documentInfo = Document.GetDocumentInfo(informacionEntrada.Id, sesion); documentoRepositorio.DocumentoAsociado = documentInfo; } documentoRepositorio.Repositorio = Repositorio.Laserfiche; documentoRepositorio.Nombre = documentoRepositorio.Directorio ? folderInfo.Name : documentInfo.Name; documentoRepositorio.Plantilla = documentInfo.TemplateName; documentoRepositorios.Add(documentoRepositorio); } return(documentoRepositorios); } return(new List <DocumentoRepositorio>()); }
protected void ExplorarDirectorio(EntryInfo informacionEntrada, string referencia, ref List <DocumentoRepositorio> listadoDocumentos) { if (informacionEntrada.EntryType == EntryType.Folder) { FolderInfo directorioLF = Folder.GetFolderInfo(informacionEntrada.Id, Sesion); var configuracionListadoEntrada = new EntryListingSettings(); FolderListing contenidoDirectorio = directorioLF.OpenFolderListing(configuracionListadoEntrada); for (int j = 1; j <= contenidoDirectorio.RowCount; j++) { EntryInfo informacionEntradaLF = contenidoDirectorio.GetEntryInfo(j); if (informacionEntradaLF.EntryType == EntryType.Document) { DocumentInfo informacionDocumentoLF = Document.GetDocumentInfo(informacionEntradaLF.Id, Sesion); DocumentoRepositorio documentoRepositorio = new DocumentoRepositorio() { Directorio = false, DocumentoAsociado = informacionDocumentoLF, IdDocumento = informacionDocumentoLF.Id.ToString(), Nombre = informacionDocumentoLF.Name, Referencia = referencia, Plantilla = informacionDocumentoLF.TemplateName, Repositorio = Repositorio.Laserfiche, Ruta = informacionDocumentoLF.Path, TipoMime = informacionDocumentoLF.MimeType }; listadoDocumentos.Add(documentoRepositorio); } else if (informacionEntradaLF.EntryType == EntryType.Folder) { ExplorarDirectorio(informacionEntradaLF, referencia, ref listadoDocumentos); } } } }
private FolderListing Get_listing(string folderpath, string dfb_token, string dfb_member_id) { if (folderpath == null) { Console.WriteLine("Empty path"); } else { string uri = "https://api.dropbox.com/1/metadata/auto" + folderpath; // +"?list=false"; WebRequest request = WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; String authheader = "Authorization:Bearer " + dfb_token; request.Headers.Add(authheader); request.Headers.Add("X-Dropbox-Perform-As-Team-Member:" + dfb_member_id); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); //serialize the json DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(FolderListing)); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer)); try { var obj = (FolderListing)ser.ReadObject(stream); // Cleanup the streams and the response. reader.Close(); dataStream.Close(); response.Close(); return(obj); } catch { FolderListing failListing = new FolderListing(); failListing.bytes = -2; return(failListing); } } catch (WebException error) { Console.WriteLine(error); } } FolderListing brokenListing = new FolderListing(); brokenListing.bytes = -1; return(brokenListing); } //end of get_listing
private FolderListing Get_listing(string folderpath, string dfb_token, string dfb_member_id) { if (folderpath == null) { Console.WriteLine("Empty path"); } else { string uri = "https://api.dropbox.com/1/metadata/auto" + folderpath; // +"?list=false"; WebRequest request = WebRequest.Create(uri); request.Method = "GET"; request.ContentType = "application/json"; String authheader = "Authorization:Bearer " + dfb_token; request.Headers.Add(authheader); request.Headers.Add("X-Dropbox-Perform-As-Team-Member:" + dfb_member_id); try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream containing content returned by the server. Stream dataStream = response.GetResponseStream(); // Open the stream using a StreamReader for easy access. StreamReader reader = new StreamReader(dataStream); // Read the content. string responseFromServer = reader.ReadToEnd(); //serialize the json DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(FolderListing)); MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(responseFromServer)); try { var obj = (FolderListing)ser.ReadObject(stream); // Cleanup the streams and the response. reader.Close(); dataStream.Close(); response.Close(); return obj; } catch { FolderListing failListing = new FolderListing(); failListing.bytes = -2; return failListing; } } catch (WebException error) { Console.WriteLine(error); } } FolderListing brokenListing = new FolderListing(); brokenListing.bytes = -1; return brokenListing; }