向项目的文件夹中写入数据流

 public void GetChargStationFileCount(HttpContext context)
        {
            var chargstationfilebll = new ChargStationFileBll();
            var cPictureMessage = new Message<Picture>();
            var fileid = context.Request.Params["id"];
            string ret = null;
            if (string.IsNullOrEmpty(fileid))
            {
                cPictureMessage.Total = 0;
                return;
            }
            var chargstationfile = new ChargStationFile
                {
                    ZhanBh = int.Parse(fileid)
                };
            try
            {
                var dt = chargstationfilebll.FindBy(chargstationfile);
                var list = ConvertHelper<Picture>.ConvertToList(dt);
                foreach (var li in list)
                {
                    var bytes = li.FileContext;
                    if (bytes == null) continue;
                    var stream = new MemoryStream(bytes);
                    var img = Image.FromStream(stream);
                    string path = AppDomain.CurrentDomain.BaseDirectory;//获取文件的相对路径
                    string filePath = path + @"ScriptspictureChargStationSaveChargeStationFile";
                    img.Save(filePath + li.Id + "." + li.FileMime);
                    var w = img.Width;
                    var h = img.Height;
                    li.Width = w;
                    li.Height = h;
                    li.FileContext = null;
                }

                cPictureMessage.Rows = list;
                ret = Jss.Serialize(cPictureMessage);

            }
            catch (Exception e)
            {
                Log.Error(e);
                throw;
            }
            context.Response.Write(ret);
原文地址:https://www.cnblogs.com/zhangwei595806165/p/3365366.html