/// <summary> /// 通过文件路径及文件名称删除文件. /// </summary> /// <param name="relativePath">文件路径</param> /// <param name="fileName">文件名称</param> public void DeleteFile(string relativePath, string fileName) { if (!DefaultStoreProvider.IsValidPathAndFileName(relativePath, fileName)) { throw new InvalidOperationException("The provided path and/or file name is invalid"); } string fullLocalPath = this.GetFullLocalPath(relativePath, fileName); if (File.Exists(fullLocalPath)) { File.Delete(fullLocalPath); } }
/// <summary> /// 创建或更新一个文件 /// </summary> /// <param name="relativePath">相对文件路径</param> /// <param name="fileName">文件名称</param> /// <param name="contentStream">The stream containing the content of the file.</param> public IStoreFile AddOrUpdateFile(string relativePath, string fileName, Stream contentStream) { if (contentStream == null || !contentStream.CanRead) { return(null); } if (!DefaultStoreProvider.IsValidPathAndFileName(relativePath, fileName)) { throw new InvalidOperationException("The provided path and/or file name is invalid."); } string fullLocalPath = this.GetFullLocalPath(relativePath, fileName); DefaultStoreProvider.EnsurePathExists(fullLocalPath, true); contentStream.Position = (long)0; using (FileStream fileStream = File.OpenWrite(fullLocalPath)) { byte[] numArray = new byte[ (int) checked ( (IntPtr)((contentStream.Length > (long)65536 ? (long)65536 : contentStream.Length)))]; while (true) { int num = contentStream.Read(numArray, 0, (int)numArray.Length); int num1 = num; if (num <= 0) { break; } fileStream.Write(numArray, 0, num1); } fileStream.Flush(); fileStream.Close(); } return(new DefaultStoreFile(relativePath, new FileInfo(fullLocalPath))); }