Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Using Modules a...Using Modules a...Help with Documents from a databaseHelp with Documents from a database
Previous
 
Next
New Post
3/26/2013 9:16 AM
 

Hi,

I have been searching for an answer to this for a long time and still can't find one.

Is it possible to retrieve a document from a database in DotNetNuke? I have code that does this in my .Net website and it works perfectly but when I created a custom module that retrieves the documents using the same code, I get an error "The remote host closed the connection. The error code is 0x80070057." Am I wasting my time trying to do this or does anyone know if it can be done. These documents are already stored in the Client's database so I can't just store them in a repository somewhere. My client is now wondering if I've made a mistake by choosing DotNetNuke as the CMS because of the limitations. I am using DNN 6.2.2.

Here is the code to retrieve the document:

public static bool openDocument(int iDocID, int languageID)
        {
            using (var ctx = Components.Data.Model.DecisionReportModel.Instance())
            {
                var doc = from d in ctx.DocumentLanguages.Include("Document").Where(dd => dd.DocumentID == iDocID && dd.LanguageID == languageID)
                          select d;

                var document = doc.FirstOrDefault();

                HttpContext.Current.Response.Buffer = false; //I've tried true as well

                HttpContext.Current.Response.Clear();
                if (document.Document.FileSize > 0)
                {
                    string strFileName = document.Document.FileName;
                    HttpContext.Current.Response.ContentType = document.Document.ContentType;
                    HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + strFileName.ToString());
                    HttpContext.Current.Response.OutputStream.Write(document.FileContent, 0, ((int)document.Document.FileSize));

                    HttpContext.Current.Response.Flush();
                    HttpContext.Current.Response.Close();
                    HttpContext.Current.Response.End();

                    return true;
                }
                return false;
            }
        }

 
New Post
3/26/2013 10:12 AM
 

Rob,

I solved this by creating a "Database" folder (using the File Manager) - then you can get the files by something like

IFileInfo file = (IFileInfo)FileManager.Instance.GetFile(...);
Stream fileContent = FileManager.Instance.GetFileContent(file);

and then write the fileContent to the output stream as you did in your code.

Best wishes
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
3/26/2013 11:53 AM
 

Hi Michael,

Does that mean that I would have to put all of my documents into this "Database" folder.

 
New Post
3/27/2013 4:42 AM
 

Rob,

yes.

Best wishes
Michael


Michael Tobisch
DNN★MVP

dnn-Connect.org - The most vibrant community around the DNN-platform
 
New Post
3/27/2013 10:24 AM
 

Unfortunately, that won't work for me. These documents are already in the database and another web application (not a DNN site) that I've created allows users to upload documents to this database while my DNN module in this application is supposed to read from this database and display these documents and any new document that gets uploaded. I could technically upload my 8 gb worth of documents to this folder that you suggested but I'd be duplicating these documents and this folder would not include and new documents that get uploaded from my user.

Thanks anyway,

 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Using Modules a...Using Modules a...Help with Documents from a databaseHelp with Documents from a database


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out