sharepoint-2013filestreamsharepointdocumentlibrary

Sharepoint document library storing files on filesystem


I'm in a bit of trouble here. Here is the context:

One of our customers asked us to develop an alternative solution to storing documents of a document library in the content database as their content database is growing too fast. They provided us with a network storage so that the documents could be stored in the filesystem instead. After googling a bit, I've found a feature called Remote Blob Storage RBS RBS, but as the references say, this is a per content database feature which is not acceptable for the context. The other option I've come up with is the use of SPItemEventReceiver so that in the ItemAdded event I could save the SPFile associated with the ListItem of the SPItemEventProperties property to the filesystem and possibly delete or truncate the SPFile object

public static void DeleteAssociatedFile(SPWeb web, SPListItem item)
{
    try
    {
        if (item == null) { throw new ArgumentNullException("item"); }

        if (item.FileSystemObjectType == SPFileSystemObjectType.File)
        {
            web.AllowUnsafeUpdates = true;

            using (var fileStream = item.File.OpenBinaryStream())
            {
                if (fileStream.CanWrite)
                {
                    fileStream.SetLength(0);
                }
            }

            item.File.Update();
        }
    }
    catch (Exception ex)
    {
        // log error message
        Logger.Unexpected("ListItemHelper.DeleteAssociatedFile", ex.Message);

        throw;
    }
    finally
    {
        web.AllowUnsafeUpdates = false;
    }
}

forcing it to not store its content into the content database. But it didn't work out. Everytime that I somehow manage to delete or truncate the SPFile associated with the ListItem, the ListItem itself either gets deleted from the document library or the file doesn't get affected by the change. So my is question is: is there a solution for this problem? Any other thoughts that could help me in this quest?

Thanks in advance!


Solution

  • As you have asked other thoughts

    1. One thing coming into my mind is one drive for business instead of network storage
    2. Another is develop custom file upload, upload the file directly to network storage and once uploaded, add an entry in SharePoint list.