Ejemplo n.º 1
0
        public static string SaveFile(byte[] data, string outputPath)
        {
            var parser = new MultipartParser(data);

            if (parser.Success)
            {
                var fileName = parser.Filename;
                if (!String.IsNullOrWhiteSpace(outputPath) && Directory.Exists(outputPath))
                {
                    Array.ForEach(Path.GetInvalidFileNameChars(), c => fileName = fileName.Replace(c.ToString(), String.Empty));
                    outputPath = Path.Combine(outputPath, fileName);
                }
                File.WriteAllBytes(outputPath, parser.FileContents);
            }
            return(outputPath);
        }
Ejemplo n.º 2
0
 public static string SaveFile(Stream input, string outputPath)
 {
     var parser = new MultipartParser(ReadToEnd(input));
     if (parser.Success)
     {
         var fileName = parser.Filename;
         if (!String.IsNullOrWhiteSpace(outputPath) && Directory.Exists(outputPath))
         {
             Array.ForEach(Path.GetInvalidFileNameChars(), c => fileName = fileName.Replace(c.ToString(), String.Empty));
             outputPath = Path.Combine(outputPath, fileName);
         }
         File.WriteAllBytes(outputPath, parser.FileContents);
     }
     return outputPath;
 }