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.

Please do help.

Waiting for response Smiley Happy

Thanks,
Divya Palivela
2 REPLIES 2

bharathi
Champ in-the-making
Champ in-the-making

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 parameters = new Dictionary();
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

muralidharand
Star Contributor
Star Contributor


string objectId = <Document Object ID> goes here
            try
                {

                    Document doc = session.GetObject(objectId) as Document;
                    ContentStream contentStream = (DotCMIS.Data.Impl.ContentStream)doc.GetContentStream();
                    using (var fileStream = File.Create(@".\" + contentStream.FileName))
                    {
                        contentStream.Stream.CopyTo(fileStream);
                    }
                    MessageBox.Show("File " + contentStream.FileName + " downloaded successfully");
                }catch(Exception ex)
                {
                    MessageBox.Show("File " + fileName + " download failed." + ex.Message);
                }


Download the sample application at https://github.com/muralidharand/AlfrescoDotCMISExamples