当前位置: 首页>>代码示例>>C#>>正文


C# UploadedFile.Stream方法代码示例

本文整理汇总了C#中UploadedFile.Stream方法的典型用法代码示例。如果您正苦于以下问题:C# UploadedFile.Stream方法的具体用法?C# UploadedFile.Stream怎么用?C# UploadedFile.Stream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UploadedFile的用法示例。


在下文中一共展示了UploadedFile.Stream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImportFile

 public void ImportFile(UploadedFile file, string dateFormat)
 {
     Method = "Import";
     Stream s = null;
     try {
         s = file.Stream();
         if (Path.GetExtension(file.Name).ToLower() == ".qif") {
             QifImporter qif = new QifImporter();
             new ImportBatchJob(this, qif, delegate() {
                 try {
                     Batch.Records = file.Content.Length;
                     Batch.Status = "Importing file " + file.Name + " as QIF";
                     Database.BeginTransaction();
                     qif.DateFormat = dateFormat;
                     qif.Import(new StreamReader(s), this);
                     Database.Commit();
                 } catch (Exception ex) {
                     throw new CheckException(ex, "Error at line {0}\r\n{1}", qif.Line, ex.Message);
                 } finally {
                     s.Dispose();
                 }
                 Message = "File " + file.Name + " imported successfully as QIF";
             });
         } else {
             CsvParser csv = new CsvParser(new StreamReader(s));
             Importer importer = Importer.ImporterFor(csv);
             Utils.Check(importer != null, "No importer for file {0}", file.Name);
             new ImportBatchJob(this, csv, delegate() {
                 try {
                     Batch.Records = file.Content.Length;
                     Batch.Status = "Importing file " + file.Name + " as " + importer.Name + " to ";
                     Database.BeginTransaction();
                     importer.DateFormat = dateFormat;
                     importer.Import(csv, this);
                     Database.Commit();
                 } catch (Exception ex) {
                     throw new CheckException(ex, "Error at line {0}\r\n{1}", csv.Line, ex.Message);
                 } finally {
                     s.Dispose();
                 }
                 Message = "File " + file.Name + " imported successfully as " + importer.Name + " to " + importer.TableName;
             });
         }
     } catch (Exception ex) {
         Log(ex.ToString());
         Message = ex.Message;
         if (s != null)
             s.Dispose();
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:50,代码来源:Settings.cs

示例2: StatementImportPost

 /// <summary>
 /// User wants to import a statement
 /// </summary>
 /// <param name="id">Account</param>
 /// <param name="format">Statement format (for pasted statement)</param>
 /// <param name="data">Pasted statement</param>
 /// <param name="file">Uploaded Qif statement</param>
 /// <param name="dateFormat">For Qif import</param>
 public void StatementImportPost(int id, string format, string data, UploadedFile file, string dateFormat)
 {
     Account account = Database.Get<Account>(id);
     checkAcctType(account.AccountTypeId, AcctType.Bank, AcctType.CreditCard);
     JArray result;
     DateTime minDate = DateTime.MaxValue;
     if (!string.IsNullOrWhiteSpace(file.Content)) {
         // They have uploaded a Qif file
         QifImporter qif = new QifImporter();
         qif.DateFormat = dateFormat;
         result = qif.ImportTransactions(new System.IO.StreamReader(file.Stream()), this);
         Utils.Check(result.Count > 0, "No transactions found");
         minDate = result.Min(i => (DateTime)i["Date"]);
     } else {
         // They have uploaded pasted data
         data = data.Replace("\r", "") + "\n";
         Utils.Check(!string.IsNullOrWhiteSpace(format), "You must enter a Statement Format");
         // See Import Help for details of format notation
         format = format.Replace("\r", "").Replace("\t", "{Tab}").Replace("\n", "{Newline}");
         string regex = format
             .Replace("{Tab}", @"\t")
             .Replace("{Newline}", @"\n");
         regex = Regex.Replace(regex, @"\{Any\}", delegate(Match m) {
             // Look at next character
             string terminator = regex.Substring(m.Index + m.Length, 1);
             switch (terminator) {
                 case @"\n":
                 case @"\t":
                     break;
                 default:
                     // Terminate "ignore any" section at next newline or tab
                     terminator = @"\t\n";
                     break;
             }
             return @"[^" + terminator + @"]*?";
         });
         regex = Regex.Replace(regex, @"\{Optional:([^}]+)\}", "(?:$1)?");
         regex = Regex.Replace(regex, @"\{([^}]+)\}", delegate(Match m) {
             // Look at next character
             string terminator = m.Index + m.Length >= regex.Length ? "" : regex.Substring(m.Index + m.Length, 1);
             switch (terminator) {
                 case @"\n":
                 case @"\t":
                     break;
                 default:
                     // Terminate field at next newline or tab
                     terminator = @"\t\n";
                     break;
             }
             // Create named group with name from inside {}
             return @"(?<" + m.Groups[1] + @">[^" + terminator + @"]*?)";
         });
         regex = "(?<=^|\n)" + regex;
         result = new JArray();
         Regex r = new Regex(regex, RegexOptions.Singleline);
         bool valid = false;
         foreach (Match m in r.Matches(data)) {
             JObject o = new JObject();
             string value = null;
             try {
                 decimal amount = 0;
                 foreach (string groupName in r.GetGroupNames()) {
                     value = m.Groups[groupName].Value;
                     switch (groupName) {
                         case "0":
                             break;
                         case "Date":
                             DateTime date = DateTime.Parse(value);
                             if (date < minDate)
                                 minDate = date;
                             o["Date"] = date;
                             break;
                         case "Amount":
                             Utils.Check(extractAmount(value, ref amount), "Unrecognised Amount {0}", value);
                             o["Amount"] = -amount;
                             break;
                         case "Payment":
                             if (extractAmount(value, ref amount))
                                 o["Amount"] = -Math.Abs(amount);
                             break;
                         case "Deposit":
                             if (extractAmount(value, ref amount))
                                 o["Amount"] = Math.Abs(amount);
                             break;
                         default:
                             o[groupName] = value;
                             break;
                     }
                 }
                 Utils.Check(o["Amount"] != null, "No Payment, Deposit or Amount");
                 Utils.Check(o["Date"] != null, "No Date");
                 valid = true;
//.........这里部分代码省略.........
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:101,代码来源:Banking.cs


注:本文中的UploadedFile.Stream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。