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?
sorry, forgot to say that the module does compile and everything works fine until it gets to myFileManager.AddFile
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).
DataProvider.Instance().UpdateFileLastModificationTime
DateTime.MinDate
Null.NullDate
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.
AddFile
Stream
System.IO.FileMode.Create
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:
Awesome! Simply post in the forums using the link below and we'll get you started.