文件流图像到文件夹 [英] Filestream image to folder

查看:81
本文介绍了文件流图像到文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件流图像到文件夹。

Filestream image to folder.

string imgname = "Pictures/" + pic1.jpg;
using (System.IO.FileStream fs = New System.IO.FileStream(Server.MapPath("imgname"), System.IO.FileMode.Append, System.IO.FileAccess.Write, System.IO.FileShare.Read, 8, System.IO.FileOptions.None)))
    {
        Byte[] byte1 = System.IO.File.ReadAllBytes(open.FileName);                                              
        fs.Write(byte1, 0, byte1.Length);
        fs.Flush();
        fs.Close();
    }



open.FileName中的错误



我尝试了什么:



尝试了不同的Byte [] byte1 scenerios。没有用于图像。


Error in "open.FileName"

What I have tried:

Tried different Byte[] byte1 scenerios. None worked for an image.

推荐答案

嗯......您正在使用Server.MapPath,所以这是一个Web应用程序。我们不知道开放是什么 - 但可能是它是一个FileUpload控件(因为如果你没有从客户端获取它,那么它可能在同一台服务器上,因此File.Copy更有效)我们不知道错误信息是什么。



但是如果它是FileUpload控件,那么FileName属性会告诉你在客户端上调用它的内容,但是你可以不读取文件 - 您必须使用SaveFile方法或FileBytes属性从控件中获取文件。由于您正在尝试编写该文件,我建议使用SaveFile方法。
Well... you are using Server.MapPath, so this is a web app. We don't know what "open" is - but the chances are it's a FileUpload control (because if you aren't getting it from the client, then it's probably on the same server, so File.Copy is more efficient) and we have no idea what the error message is.

But if it is a FileUpload control, then the FileName property tells you what it is called on the client, but you can't read the file - you have to get the file from the control with the SaveFile method or the FileBytes property. Since you are trying to write the file, I'd suggest the SaveFile method.


这篇关于文件流图像到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆