DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Switching to FileManager

Sort:
You are not authorized to post a reply.





New Around Here





    hi -- I've inherited a DNN website that mostly consists of custom modules.

    In trying to upgrade the site, I found a class that relies heavily on FileController to add files to the system and I've had to rewrite some of the code. Most of it I've figured out but I'm completely stumped on this one method and can't find an example anywhere.

    The old code was this:

    System.IO.FileInfo fi = new System.IO.FileInfo(mySecuredFilename);
                    String contentType = FileManager.Instance.GetContentType(fileExtension);
                    DotNetNuke.Services.FileSystem.FileInfo myFileInfo = new DotNetNuke.Services.FileSystem.FileInfo();
                    myFileInfo.FileName = fi.Name.Replace(Globals.glbProtectedExtension, "");
                    myFileInfo.Extension = fileExtension;
                    myFileInfo.ContentType = contentType;
                    myFileInfo.Size = Convert.ToInt32(fi.Length);
                    myFileInfo.FolderId = myFolderId;
                    myFileInfo.PortalId = PortalId;
                    myFileInfo.Width = 0;
                    myFileInfo.Height = 0;
                    myFileInfo.Folder = myFolderInfo.FolderName;

                    try
                    {
                        myFileId = myFileController.AddFile(myFileInfo);
                    } catch (Exception exc)
                    {

     

    I'm stumped on how to use the FileManager.AddFile method properly. I found the following but it throws some kind of date error:

    System.IO.FileStream myStream = new System.IO.FileStream(myFileName, System.IO.FileMode.Create);

                try
                {
                    
                    myFileManager.AddFile(myFolderInfo, myFileName, myStream);
                }
                catch (Exception ex)
                 {

                }

     

    Could someone please give me a working example of how to add a file with FileManager?

     






    Veteran Member





      I'm assuming that the module compiles. Is that right?

      What is the error?
      Joe Craig
      DNN MVP
      Patapsco Research Group





      New Around Here





        hi Joe,

        The error is:
        "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM."

        I'm pretty stumped on why it would throw a date error.





        New Around Here





          sorry, forgot to say that the module does compile and everything works fine until it gets to myFileManager.AddFile






          Veteran Member





            Is there a date field that you didn't initialize?
            Joe Craig
            DNN MVP
            Patapsco Research Group





            New Around Here





              not that I can see. When I examine FolderInfo properties, all the date fields contain dates (UpdatedOn, CreatedOn etc)





              Advanced Member





                Can you post the full stack trace from the exception? That would help narrow down which part of the code is throwing the exception. For example, if it's the call to DataProvider.Instance().UpdateFileLastModificationTime then the issue has to do with how the folder provider gets the last modified time (for example, if a custom folder provider returns DateTime.MinDate instead of Null.NullDate).

                DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





                New Around Here





                  I'm not even clear what FileManager is doing -- adding a record of the file to a db table? The file (a spreadsheet) has already been saved into a folder at this point.

                  sorry to be murky but I didn't create this module and not quite sure why the AddFile is being called





                  Advanced Member





                    AddFile may be used to create a file record in the database, but it can also be used to update the contents of a file. Since you're passing a Stream, I think it's probably attempting to update the contents of the file to match the contents in the Stream. I would guess that you want a read-only Stream rather than a System.IO.FileMode.Create Stream so that the code can read the contents, but I don't think that would be related to the date error you're getting now.

                    DNN partner specializing in custom, enterprise DNN development https://engagesoftware.com/showcase





                    New Around Here





                      hi Brian, thanks for that info.

                      The stack trace is:

                      at DotNetNuke.Services.FileSystem.FileManager.AddFile(IFolderInfo folder, String fileName, Stream fileContent, Boolean overwrite, Boolean checkPermissions, Boolean ignoreWhiteList, String contentType, Int32 createdByUserID)
                      at DotNetNuke.Services.FileSystem.FileManager.AddFile(IFolderInfo folder, String fileName, Stream fileContent)
                      at FileUtils.AddFileToSystem(String myFileName, Int32 PortalId, String folderPath, String fileExtension) in [my path to App_Code] \FileUtils\FileUtils.cs:line 162
                      You are not authorized to post a reply.

                      These Forums are dedicated to the discussion of DNN Platform.

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

                      1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
                      2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
                      3. 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.
                      4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
                      5. No Flaming or Trolling.
                      6. No Profanity, Racism, or Prejudice.
                      7. Site Moderators have the final word on approving / removing a thread or post or comment.
                      8. English language posting only, please.

                      Would you like to help us?

                      Awesome! Simply post in the forums using the link below and we'll get you started.

                      Get Involved