We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

ASP.net Word Manipulation

OK, I am wanting to pull a template from SQL, fill in some bookmarks, from SQL and let the user add information to the document and the save the document back to the database. Are these functions doable within a browser such as IE 7

This message was posted using Email2Forum by Merit.

Hi
Thanks for your inquiry.

  1. You can extract and save document into the database using the following code:
/// 
/// This example shows how to write document into the database.
/// 
public void Example002()
{
    // Create connction
    string connectionString = "server=Web1;database=TestDB;uid=sa;pwd=pass;";
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
    // Open the DOC file using Aspose.Words.
    Document doc = new Document(@"C:\Temp\in.doc");
    // ...You can merge data/manipulate document content here.
    MemoryStream stream = new MemoryStream();
    // Save document to memorystream
    doc.Save(stream, SaveFormat.Doc);
    // Create sql command
    string commandString = "INSERT INTO [Documents] VALUES(@Doc)";
    System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(commandString, conn);
    // Add paramenter @Doc
    command.Parameters.AddWithValue("Doc", stream.GetBuffer());
    // Open connection
    conn.Open();
    // Write document to DB
    command.ExecuteNonQuery();
    // Close DB connection
    conn.Close();
}
/// 
/// This example shows how to read document from the database.
/// 
public void Example003()
{
    // Create connction
    string connectionString = "server=Web1;database=TestDB;uid=sa;pwd=dsa43r;";
    System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(connectionString);
    // Create DataSet
    DataSet ds = new DataSet();
    // Create sql command
    string commandString = "SELECT Document FROM Documents WHERE ID=2";
    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);
            FileStream file = new FileStream(@"C:\Temp\out.doc", FileMode.Create);
            stream.WriteTo(file);
            file.Close();
            stream.Close();
            Document doc = new Document(stream);
            doc.Save(@"C:\Temp\out.doc");
        }
    }
}
  1. Aspose.Words is a class library for working with documents programmatically. If you need that user will be able to edit document on your web page then you can try using Aspose.Editor. Please see the following link for more information.
    https://products.groupdocs.com/editor/net/

Best regards,