Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a word document ,how can i store it and retrieve it


can i do like storing the document in the project and path it database ,then how to restive that word document then
Posted

1 solution

You can store file either in BLOB format or in directory, to show word document in ASP.NET you need to use Response object
see below snippet
C#
//store file in DB
public static void databaseFilePut(string varFilePath) {
    byte[] file;
    using (var stream = new FileStream(varFilePath, FileMode.Open, FileAccess.Read)) {
        using (var reader = new BinaryReader(stream)) {
            file = reader.ReadBytes((int) stream.Length);       
        }          
    }
    using (var varConnection = Locale.sqlConnectOneTime(Locale.sqlDataConnectionDetails))
    using (var sqlWrite = new SqlCommand("INSERT INTO TABLE1(COL1) Values(@File)", varConnection)) {
        sqlWrite.Parameters.Add("@File", SqlDbType.VarBinary, file.Length).Value = file;
        sqlWrite.ExecuteNonQuery();
    }
}

Here the column datatype should be VARBINARY(MAX)
IFRAME is a nice control to show word file in browser, Or if you don't want your file to get edit you can save it as HTML and the show it
 
Share this answer
 
Comments
Member 11970398 30-Dec-15 4:55am    
sorry i could not understand properly
i am storing the image in the project and the path in database how to display that word document in view
koolprasad2003 30-Dec-15 5:34am    
You can use IFAME control to show word file in application
Member 11970398 30-Dec-15 5:44am    
yeah i am using that but its downloading that image directly .i want to show that image in pop up
koolprasad2003 30-Dec-15 6:01am    
share your code so that I can have some idea about it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900