Exemplo n.º 1
0
        /// <summary>
        /// 下载项目资源
        /// </summary>
        /// <param name="id"></param>
        /// <param name="projectId"></param>
        /// <param name="operateType"></param>
        /// <returns></returns>
        public ActionResult DownLoadResource(long id, long projectId, string operateType)
        {
            var resource = ProjectService.GetResourceById(id);

            if (resource == null)
            {
                return
                    (Content(
                         "<script >alert('对不起,该文件已被删除,无法下载!');self.location='/Project/SummaryData?projectId=" + projectId +
                         "&operateType=" + operateType + "'</script >", "text/html"));
            }
            var sourceUrl = FileStreamHelper.GetPathAtApplication(resource.FilePath);

            byte[] data;
            try
            {
                var fs = new FileStream(sourceUrl, FileMode.Open, FileAccess.Read);
                data = new byte[(int)fs.Length];
                fs.Read(data, 0, data.Length);
                fs.Close();
            }
            catch
            {
                return
                    (Content(
                         "<script >alert('对不起,该文件已被删除,无法下载!');self.location='/Project/SummaryData?projectId=" + projectId +
                         "&operateType=" + operateType + "'</script >", "text/html"));
            }
            return(File(data, "application/octet-stream", resource.FileName));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 写入日志到本地硬盘
        /// </summary>
        /// <param name="concent">记录内容</param>
        /// <param name="userAccount">操作用户</param>
        /// <param name="logType">日志类型</param>
        public void Ilog(string concent, string userAccount = "", LogTypeEnum logType = LogTypeEnum.Info)
        {
            string       token   = DateTime.Now.ToString("yyyyMMddHH");
            string       logRoot = FileStreamHelper.GetPathAtApplication("log");
            StreamWriter sw      = new StreamWriter(logRoot, true);

            sw.WriteLine(concent);
            sw.Close();//写入
        }