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

kaynezhang
World-Class Innovator
World-Class Innovator
I'm sorry I'm not clear about what you mean,If you want to download content using dotcmis,you can do it like this:
1.Get the IDocument object ,for example use GetObjectByPath() method of ISession.
2.Get the content stream of this document using IDocument.GetContentStream() method
3.Get System.io.stream from content stream and write it to file

Hi kaynezhang..

Thanks for your post. Please explain me how to download a file using dotcmis with tree view. If I click on file name in folder it needs to be downloaded in local . Please help me.

Finally What I need is if I click on any file in tree view it needs to be downloaded in local. Please help me Smiley Happy

kaynezhang
World-Class Innovator
World-Class Innovator
When user click on file item in treeview,send request to your c# code behind and pass file item's node id or node path as parameter.
In c# code behind get  node id or node path parameter,get document object using ISession 's GetObjectByPath() or ISession's GetObject() method of dotcmis api.
Then.Get the content stream of this document using IDocument.GetContentStream() method
Last write content stream into response.

Thanks Kayne.. Smiley Happy I will try to fix that one.

Hi Team,


I am new to Alfresco. I have successfully done with uploading documents into alfresco using dotcmis and displayed that in grid view. I am unable to download that. Please Please help me to achieve that. I have followed the above procedure.

In alfrescoupload page :

     <asp:GridView ID="grdDisplay" runat="server" AutoGenerateColumns="False" CellPadding="0"
                    CellSpacing="0" CssClass="grid table table-bordered table-hover">
                    <AlternatingRowStyle BackColor="White" />
                    <Columns>
                        <asp:BoundField DataField="ClaimName" HeaderText="Claim Name" />
                        <asp:HyperLinkField DataTextField="Name" HeaderText="Document Name" DataNavigateUrlFields="ClaimName, Name" DataNavigateUrlFormatString="~/DownloadFile.aspx?Id={0}&Name={1}" />
                        <asp:BoundField DataField="LastModifiedBy" HeaderText="LastModifiedBy" />
                    </Columns>
                </asp:GridView>

Code Behind :     dt.Rows.Add(treeItem.Item.Name, treeItem.Item.LastModifiedBy,tree.Item.Name);
               

In Download.aspx :

  protected void Page_Load(object sender, EventArgs e)
        {
            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";
            string getUserID = Request.QueryString["Id"];
            //int userID = Convert.ToInt32(getUserID);
            string getDocName = Request.QueryString["Name"];
            SessionFactory factory = SessionFactory.NewInstance();
            ISession session = factory.GetRepositories(parameters)[0].CreateSession();
            IObjectId id = session.CreateObjectId(getUserID);
            IDocument doc = session.GetObject(id) as IDocument;
            IContentStream contentStream = doc.GetContentStream();
I tried like that. But I was unable to pass id as parameter. Please help me.


Thanks alot

Thanks,

Bharathi

bharathi
Champ in-the-making
Champ in-the-making
Please help me in to achieve the downloading documents in alfresco using cmis with c#.

Waiting for response Smiley Happy

Hello , u could solve your problem , I need to get a pdf file q this alfresco and put in a directory on my server , I use .NET.

cnarvaez
Champ in-the-making
Champ in-the-making
Hi I´m using Alfresco 5 Community Manager, and need make the same process, this is upload a document from a desktop application building on c#. So if you try and make this please share the information