Sign In  Sign Up Live-Chat

Aspose.Words.Document and MemoryStream object.

Last post 07-31-2008, 7:14 AM by alexey.noskov. 1 replies.
Sort Posts: Previous Next
  •  07-31-2008, 7:03 AM 137732

    Aspose.Words.Document and MemoryStream object.

    Hi!

    I wonder if it is possible to instantiate an Aspose.Words.Document object passing a MemoryStream object as the parameter.

    In the examples in your documentation and also based on my tests I found it possible to either pass a path to a file or pass a FileStream object which is equivalent to passing a path to the file.

    But in my case I retreive the file contents from the database (SharePoint object model). Then I can save the contents in the MemoryStream that supports seeking. However I couldn' t make that work because it simply hangs on the Aspose.Words.Document initialization.

    In this sceanrio I have to save the memory contents to a file and only then pass the file to the Aspose object. Do you see a possibility to really pass a MemoryStream so I would avoid making extra operations?

    thank you for your help.


    This message was posted using Page2Forum from Opening and Creating Documents - Aspose.Words for .NET and Java
     
  •  07-31-2008, 7:14 AM 137737 in reply to 137732

    Re: Aspose.Words.Document and MemoryStream object.

    Hi

     

    Thanks for your inquiry. Yes of course you can do this. For example see the following code that shows how to open document from data base:

     

    public void Example003()

    {

        //Create connction

        string connectionString = "server=Web1;database=TestDB;uid=sa;pwd=pass;";

        System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);

        //Create DataSet

        DataSet ds = new DataSet();

        //Create sql command

        string commandString = "SELECT FileContent FROM Documents WHERE ID=1";

        System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(commandString, conn);

        //Create data adapter

        System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter(command);

        //Open connection

        conn.Open();

        //Read dataset

        adapter.Fill(ds);

        conn.Close();

        //Save document to hard disk

        if (ds.Tables.Count > 0)

        {

            if (ds.Tables[0].Rows.Count > 0)

            {

                byte[] buffer = (byte[])ds.Tables[0].Rows[0][0];

                MemoryStream stream = new MemoryStream(buffer);

                Document doc = new Document(stream);

                //Do something....

                //................

                //Do something....

                doc.Save(@"C:\Temp\out.doc");

            }

        }

    }

     

    Hope this helps.

     

    Best regards.


    Alexey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML