Example #1
0
 public virtual void AddItemTemplate(string category, string templateName, Stream templateStream, Stream thumbnailStream)
 {
     if (GetItemTemplate(category, templateName) != null)
     {
         throw new Exception("该事物已存在.");
     }
     var physicalPath = GetCategoryPhysicalPath(category);
     IOUtility.EnsureDirectoryExists(physicalPath);
     var itemFile = Path.Combine(physicalPath, templateName + FileExtension);
     var thumbnail = Path.Combine(physicalPath, templateName + ".png");
     templateStream.SaveAs(itemFile);
     if (thumbnailStream != null && itemFile.Length > 0)
     {
         MemoryStream ms = new MemoryStream();
         Bsc.Dmtds.Common.Drawing.ImageTools.ResizeImage(thumbnailStream, ms, ImageFormat.Png, 100, 100, true, 100);
         ms.Position = 0;
         ms.SaveAs(thumbnail);
     }
 }
Example #2
0
        public static string UploadFileToDirectory(MemoryStream file, string directoryName, string fileName)
        {
            if (file == null)
                throw new Exception("Empty file");

            var urlPath = GenerateUrlPathForFile(directoryName, fileName);
            file.SaveAs(urlPath.Path);
            return urlPath.Url;
        }