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


C# FileStream.ReadAllBytes方法代码示例

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


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

示例1: CreateOrUpdateDetailCollectionItem

        protected override void CreateOrUpdateDetailCollectionItem(ContentItem contentItem, PropertyData existingDetail, Control editor, out object newDetail)
        {
            FancyFileUpload fileEditor = (FancyFileUpload)editor;
            LinkProperty existingFileProperty = existingDetail as LinkProperty;
            if (fileEditor.HasNewOrChangedFile)
            {
                // Add new file.
                File newFile = null;
                if (existingFileProperty != null)
                    newFile = existingFileProperty.LinkedItem as File;
                if (newFile == null)
                {
                    newFile = CreateNewItem();
                    newFile.Name = Name + Guid.NewGuid();
                    newFile.AddTo(contentItem);
                }

                // Populate FileData object.
                newFile.FileName = fileEditor.FileName;
                string uploadFolder = BaseFileUploadHandler.GetUploadFolder(fileEditor.Identifier);
                string uploadedFile = Path.Combine(uploadFolder, fileEditor.FileName);
                using (FileStream fs = new FileStream(uploadedFile, FileMode.Open))
                {
                    newFile.Data = fs.ReadAllBytes();
                    newFile.ContentType = MimeUtility.GetMimeType(newFile.Data);
                    newFile.Size = fs.Length;
                }

                // Delete temp folder.
                System.IO.File.Delete(uploadedFile);
                Directory.Delete(uploadFolder);

                newDetail = newFile;

                if (existingFileProperty != null)
                    HandleUpdatedFile(newFile);
            }
            else
            {
                newDetail = null;
            }
        }
开发者ID:dpawatts,项目名称:zeus,代码行数:42,代码来源:MultiFileUploadEditorAttribute.cs

示例2: UpdateItem

        public override bool UpdateItem(IEditableObject item, Control editor)
        {
            FancyFileUpload fileUpload = (FancyFileUpload) editor;
            File file = (File) item;

            bool result = false;
            if (fileUpload.HasDeletedFile)
            {
                file.Data = null;
                result = true;
            }
            else if (fileUpload.HasNewOrChangedFile)
            {
                // Populate File object.
                file.FileName = fileUpload.FileName;
                string uploadedFile = GetUploadedFilePath(fileUpload);
                using (FileStream fs = new FileStream(uploadedFile, FileMode.Open))
                {
                    file.Data = fs.ReadAllBytes();
                    file.ContentType = MimeUtility.GetMimeType(file.Data);
                    file.Size = fs.Length;
                }

                // Later, we will change the name, if this is a child property.
                file.Title = fileUpload.FileName;
                file.Name = fileUpload.FileName.ToLower();

                // Delete temp folder.
                System.IO.File.Delete(uploadedFile);
                Directory.Delete(BaseFileUploadHandler.GetUploadFolder(fileUpload.Identifier));

                result = true;
            }

            return result;
        }
开发者ID:dpawatts,项目名称:zeus,代码行数:36,代码来源:FileUploadEditorAttribute.cs

示例3: AssertFileEqual

        // Asserts that the contents of two files are equal.
        void AssertFileEqual(string fileName1, string fileName2)
        {
            byte[] content1, content2;
            using (var r1 = new FileStream(fileName1, FileMode.Open))
            {
                content1 = r1.ReadAllBytes();
            }
            using (var r1 = new FileStream(fileName2, FileMode.Open))
            {
                content2 = r1.ReadAllBytes();                
            }

            Assert.Equal(content1, content2);
        }
开发者ID:Newtopian,项目名称:nuget,代码行数:15,代码来源:NuGetPushCommandTest.cs

示例4: PutPackage

        public HttpResponseMessage PutPackage(HttpRequestMessage message)
        {
            if (!Request.Content.IsMimeMultipartContent())
            {
                return new HttpResponseMessage(HttpStatusCode.BadRequest);
            }

            var provider = new MultipartFormDataStreamProvider(Path.GetTempPath());

            try
            {
                message.Content.ReadAsMultipartAsync(provider).Wait();

                foreach (var file in provider.FileData)
                {
                    using (var fileStream = new FileStream(file.LocalFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 1024*1024))
                    {
                        var bytes = fileStream.ReadAllBytes();
                        Package package;
                        if (!packageBuilder.TryBuild(bytes, out package))
                        {
                            return new HttpResponseMessage(HttpStatusCode.BadRequest);
                        }

                        if (packageService.Any(package.Id, package.Version))
                        {
                            break;
                        }

                        blobService.Upload(GetBlobScope(package), package.BlobId, bytes);
                        packageService.Add(package);
                    }
                }
                return new HttpResponseMessage(HttpStatusCode.OK);
            }
            catch (Exception)
            {
                return new HttpResponseMessage(HttpStatusCode.InternalServerError);
            }
        }
开发者ID:Pliner,项目名称:TinyFeed,代码行数:40,代码来源:PackagesController.cs


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