public static long CopyFile(IFileStorageProviderDataProvider dataProvider, Guid oldPhysicalFileID, Guid newPhysicalFileID, string extensionName) { long result = 0; IFileStorageProvider oldProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, oldPhysicalFileID, extensionName); IFileStorageProvider newProvider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, CurrentConfigSetting, newPhysicalFileID, extensionName); if (oldProvider != null && newProvider != null) { try { byte[] buffer = GetCacheBuffer(DefaultBufferSize); int readLen = oldProvider.Read(buffer, 0, DefaultBufferSize); while (readLen > 0) { newProvider.Write(buffer, 0, readLen); readLen = oldProvider.Read(buffer, 0, DefaultBufferSize); } result = newProvider.Length; } finally { oldProvider.Close(); newProvider.Close(); } } return(result); }
public static long WriteFile(IFileStorageProviderDataProvider dataProvider, Guid physicalFileID, string extensionName, long position, byte[] writeData) { long result = 0; IFileStorageProvider provider = FileStorageProviderFactory.CreateFileStorageProvider(dataProvider, physicalFileID, extensionName); if (provider != null) { try { int length = 0; if (writeData != null) { length = writeData.Length; } if (length > 0) { provider.Seek(position, System.IO.SeekOrigin.Begin); provider.Write(writeData, 0, length); result = provider.Length; } } finally { provider.Close(); } } return(result); }