Friday, February 22, 2013

Can´t upload a new attachement in DNN 6 with forum 5.0.3

Today one of my friend pinged me to help on an issue with DNN forum module(05.00.03), he was using it on DNN 06.01.05. Problem was "Upload new attachment failing repeatedly with some exception". He was getting below exception:

Error: is currently unavailable. DotNetNuke.Services.Exceptions.ModuleLoadException: The underlying system threw an exception. ---> DotNetNuke.Services.FileSystem.FolderProviderException: The underlying system threw an exception. ---> System.ArgumentNullException: Value cannot be null. Parameter name: content at DotNetNuke.Services.FileSystem.StandardFolderProvider.AddFile(IFolderInfo folder, String fileName, Stream content) at DotNetNuke.Services.FileSystem.FileManager.MoveFile(IFileInfo file, IFolderInfo destinationFolder) --- End of inner exception stack trace --- at DotNetNuke.Services.FileSystem.FileManager.MoveFile(IFileInfo file, IFolderInfo destinationFolder) at DotNetNuke.Common.Utilities.FileSystemUtils.MoveFile(String strSourceFile, String strDestFile, PortalSettings settings) at DotNetNuke.Modules.Forum.WebControls.AttachmentControl.cmdUpload_Click(Object sender, EventArgs e) --- End of inner exception stack trace ---

So as usual firstly I googled the error and found that many people are having similar error, but none of them were having a solution so I thought that it might be some permissions issue and messed up with folder permissions, but all failed.

So finally I debugged the code and found that line that was breaking was calling method "FileSystemUtils.MoveFile" which got deprecated in DNN 6 

So I replaced it with method call for "RenameFile" and there you go!!

Below is the culprit line under method cmdUpload_Click in file "AttachmentControl.ascx.vb"
FileSystemUtils.MoveFile(ParentFolderName + FileName, ParentFolderName + destFileName, PortalSettings)

 and here is its replacement

DotNetNuke.Services.FileSystem.FileManager.Instance.RenameFile(DotNetNuke.Services.FileSystem.FileManager.Instance.GetFile(DotNetNuke.Services.FileSystem.FolderManager.Instance.GetFolder(PortalId, BaseFolder), FileName), destFileName)


If you are also having this error, then just download the module's source code from codeplex, open it in visual studio, replace lines as I mentioned, build this module. Now go to your filesystem, grab new DLL for forum module and replace it in your DNN apps bin directory.

Sorry I forgot to write earlier, please take backup before doing this to your production site.

Hope this will help!!

Thanks,
Ravi

About Me

My photo
Delhi, India
Fun, music, travel and nature loving, always smiling, computer addict!!