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


C# IFile.OpenStream方法代码示例

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


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

示例1: Post

 public OperationResult Post(IFile file)
 {
     return new OperationResult.SeeOther
         {
             RedirectLocation = typeof(UploadedFile).CreateUri(new { id = this.ReceiveStream(file.ContentType, file.OpenStream()) })
         };
 }
开发者ID:endjin,项目名称:openrasta-stable,代码行数:7,代码来源:UploadedFileHandler.cs

示例2: Post

    // "id" is issue ID
    public object Post(int id, AddAttachmentArgs args, IFile attachment = null)
    {
      return ExecuteInUnitOfWork(() =>
        {
          Issue issue = IssueRepository.Get(id);
          Attachment att;
          if (attachment != null)
          {
            using (Stream s = attachment.OpenStream())
            {
              byte[] content = s.ReadAllBytes();
              att = new Attachment(issue, args.Title, args.Description, content, attachment.ContentType.MediaType);
            }
          }
          else
          {
            att = new Attachment(issue, args.Title, args.Description, null, null);
          }

          AttachmentRepository.Add(att);

          Uri attUrl = typeof(AttachmentResource).CreateUri(new { id = att.Id });

          return new OperationResult.Created { RedirectLocation = attUrl };
        });
    }
开发者ID:paulswartz,项目名称:Mason,代码行数:27,代码来源:IssueAttachmentsHandler.cs

示例3: File

        public void File(IFile file, string name)
        {
            string contentType = "";
              string filename = Path.GetFileName(file.Filename ?? "unknown");
              string asciiFilename = Regex.Replace(filename, @"[^\u0000-\u007F]", "x");
              string filenameFormat = string.Format("; filename=\"{0}\"", asciiFilename);
              if (asciiFilename != filename && Settings != null && Settings.EnableNonAsciiCharactersInMultipartFilenames)
              {
            string utf8Filename = HttpUtility.UrlEncode(filename, Encoding.UTF8);
            filenameFormat += string.Format("; filename*=UTF-8''{0}", utf8Filename);
              }
              if (file.ContentType != null)
            contentType = string.Format("\r\nContent-Type: {0}", file.ContentType);

              string header = string.Format(@"
            --{0}
            Content-Disposition: form-data; name=""{1}""{2}{3}

            ", Boundary, name, filenameFormat, contentType);

              // FIXME: escaping name and filename

              Writer.Write(header);
              Writer.Flush();
              using (Stream s = file.OpenStream())
              {
            s.CopyTo(Output);
              }
        }
开发者ID:JornWildt,项目名称:Ramone,代码行数:29,代码来源:MultipartFormDataPropertyVisitor.cs

示例4: Post

        public OperationResult Post(DocumentInfo doc, IFile sentFile)
        {
            doc.Id = Database.Documents.Max(x => x.Id) + 1;
            doc.FileName = sentFile.FileName;
            using (var reader = new BinaryReader(sentFile.OpenStream()))
                doc.Data = reader.ReadBytes((int)sentFile.Length);
            doc.LastModifiedTimeUTC = DateTime.UtcNow;
            doc.DataHref = new DocumentData { Id = doc.Id }.CreateUri();
            var createdUri = doc.CreateUri();
            Database.Documents.Add(doc);

            return new OperationResult.Created
                       {
                           RedirectLocation = createdUri,
                           ResponseResource = "Document created at " + createdUri
                       };
        }
开发者ID:openrasta,项目名称:rest-workshop-1,代码行数:17,代码来源:DocumentLibraryHandler.cs

示例5: Post

    public object Post(int id, UpdateAttachmentArgs args, IFile attachment = null)
    {
      return ExecuteInUnitOfWork(() =>
      {
        Attachment a = AttachmentRepository.Get(id);
        if (attachment == null)
          a.Update(args.Title, args.Description);
        else
        {
          // Kick NHibernate in the b*lls to make sure lazy loaded property is loaded and updated
          byte[] dummy = a.Content;

          using (Stream s = attachment.OpenStream())
          {
            byte[] content = s.ReadAllBytes();
            a.Update(args.Title, args.Description, content, attachment.ContentType.ToString());
          }
        }
        return ReadAttachmentResource(id);
      });
    }
开发者ID:paulswartz,项目名称:Mason,代码行数:21,代码来源:AttachmentHandler.cs

示例6: Post

    // "id" is project ID
    public object Post(int id, AddIssueArgs args, IFile attachment = null)
    {
      return ExecuteInUnitOfWork(() =>
      {
        Project p = ProjectRepository.Get(id);

        Issue i = new Issue(p, args.Title, args.Description, args.Severity);
        IssueRepository.Add(i);

        if (args.Attachment != null && attachment != null)
        {
          using (Stream s = attachment.OpenStream())
          {
            byte[] content = s.ReadAllBytes();
            Attachment att = new Attachment(i, args.Attachment.Title, args.Attachment.Description, content, attachment.ContentType.MediaType);
            AttachmentRepository.Add(att);
          }
        }

        Uri issueUrl = typeof(IssueResource).CreateUri(new { id = i.Id });

        return new OperationResult.Created { RedirectLocation = issueUrl };
      });
    }
开发者ID:paulswartz,项目名称:Mason,代码行数:25,代码来源:ProjectIssuesHandler.cs


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