System.IO.File.OpenWrite C# (CSharp) Méthode

OpenWrite() public static méthode

public static OpenWrite ( string path ) : System.IO.FileStream
path string
Résultat System.IO.FileStream
        public static System.IO.FileStream OpenWrite(string path) { throw null; }
        public static byte[] ReadAllBytes(string path) { throw null; }

Same methods

File::OpenWrite ( String path ) : FileStream

Usage Example

        public async Task SaveImage(Image image, Action <long, long?> report, Action <string> done)
        {
            var url    = this.ImageEndpoint(image.DirectoryName, image.Name);
            var buffer = new byte[80 * 1024];
            var read   = 0;
            var index  = 0l;

            var request  = WebRequest.Create(url);
            var response = await request.GetResponseAsync();

            try
            {
                using (var content = response.GetResponseStream())
                {
                    using (var target = File.OpenWrite($@"C:\temp\{image.Name}"))
                    {
                        while ((read = await content.ReadAsync(buffer, 0, buffer.Length,
                                                               new System.Threading.CancellationToken())) > 0)
                        {
                            await target.WriteAsync(buffer, 0, read, new System.Threading.CancellationToken());

                            index += read;
                            report(index, response.ContentLength);
                        }
                    }
                }
                done(null);
            }
            catch (Exception e)
            {
                done(e.Message);
                return;
            }
        }
All Usage Examples Of System.IO.File::OpenWrite