cancel
Showing results for 
Search instead for 
Did you mean: 

How to download individual files in alfresco cmis using c#?

divyabharathipa
Champ in-the-making
Champ in-the-making
Hello Team,

I have two questions here . Please help me to sort out those problems :

1) I have uploaded files into alfresco cmis using c# . After uploading I am displaying it in a table format or tree view format. But I am unable to view those files in a folder structure. How to display like :
       + Folder Name
       + Folder Name1
       + Folder Name2
=============================
       Folder Name
           – File1
           – File2
Like that I want to display.

and coming to my second requirement

If I click on File1 It needs to be one dialog like whether you want to open file or save file ?

If I select save it needs to save it in local.

I tried like :
<asp:TreeView ID="TreeView1" runat="server"></asp:TreeView>

Code Behind :

foreach (ICmisObject item in childrens)
            {
                TreeNode node = new TreeNode(item.Name);
                TreeView1.Nodes.Add(node);
                ConnectingUsingAtomPub_FolderNavigation(item.Name);
            }
   private void ConnectingUsingAtomPub_FolderNavigation(string p)
        {
            Dictionary<string, string> parameters = new Dictionary<string, string>();
            parameters[DotCMIS.SessionParameter.BindingType] = BindingType.AtomPub;
            parameters[DotCMIS.SessionParameter.AtomPubUrl] = "http://127.0.0.1:8080/alfresco/cmisatom";
            parameters[DotCMIS.SessionParameter.User] = "admin";
            parameters[DotCMIS.SessionParameter.Password] = "root";
            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
            IFolder root = session.GetRootFolder();
            Response.Write("<table width=100>");
            Response.Write("<tr><td>Name</td><td>LastModifiedby</td></tr>");

            foreach (ITree<IFileableCmisObject> t in root.GetDescendants(-1))
            {

                if (t.Item.Name == p.ToString())
                {

                    PrintTree(t);
                }
            }
        }

        private void PrintTree(ITree<IFileableCmisObject> tree)
        {
           // Response.Write("<tr><td> " + tree.Item.Name + "</td><td>" + tree.Item.LastModifiedBy + "</tr>");
            TreeView1.Nodes.Add(new TreeNode(tree.Item.Name));
            if (tree.Children != null)
            {
                foreach (ITree<IFileableCmisObject> treeItem in tree.Children)
                {
                    PrintTree(treeItem);
                }
            }
}
 

Please do help.

Waiting for response Smiley Happy

Thanks,
Divya Palivela
12 REPLIES 12

muralidharand
Star Contributor
Star Contributor
Hi,
Here is the sample C# which I have used to upload an image file from .net windows application to Alfresco Repo using CMIS.


IDictionary<string, object> DocumentProperties = new Dictionary<string, object>();
DocumentProperties[PropertyIds.Name] = FileName;
DocumentProperties[PropertyIds.ObjectTypeId] = "cmis:document";
Stream temp = new MemoryStream(content);
ContentStream contentStream = new ContentStream();
contentStream.FileName = FileName;
contentStream.MimeType = "image/jpeg";
contentStream.Length = content.Length;
contentStream.Stream = new MemoryStream(content);
IDocument doc = documentTypeFolderRef.CreateDocument(DocumentProperties, contentStream, DotCMIS.Enums.VersioningState.Major);

cnarvaez
Champ in-the-making
Champ in-the-making
Thanks.!!!

trola
Champ in-the-making
Champ in-the-making
Here is my code for downloading file from alfresco using CMIS.


Document doc = ((Document)session.GetObjectByPath(path));
IContentStream bla = doc.GetContentStream();
           
byte[] b = null;
using (MemoryStream ms = new MemoryStream())
{
     int count = 0;
     do
     {
           byte[] buf = new byte[1024];
           count = bla.Stream.Read(buf, 0, 1024);
           ms.Write(buf, 0, count);
     } while (bla.Stream.CanRead && count > 0);
    
     b = ms.ToArray();
}

SaveFileDialog sfd = new SaveFileDialog();
if (sfd.ShowDialog() == true)
      File.WriteAllBytes(sfd.FileName, b);