protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
        System.Web.HttpFileCollection uploadFiles = request.Files;//获取需要上传的文件
    System.Web.HttpPostedFile theFile;
    string savepath = Server.MapPath(".") + "\\templateFile\\";
     if (uploadFiles.Count == 0)
     {
         response.Write("没有文件上传!");
     }
     else
     {
         for (int i = 0; i < uploadFiles.Count; i++)
         {
             theFile = uploadFiles[i];
             if (uploadFiles.GetKey(i) == "upLoadFile")
             {
                 string myfileName = Request.Params["filename"];
                 myfileName = Server.UrlDecode(myfileName);
                 theFile.SaveAs(savepath + theFile.FileName);
                 response.Write("保存成功!");
             }
         }
     }
 }
     }
Beispiel #2
0
        /// <summary>
        ///  ��֤�ļ��ϴ���ʽ
        /// </summary>
        /// <param name="files"> files ���� </param>
        /// <param name="controlName">�ؼ�nameֵ</param>
        /// <param name="allowExtensions">�ϴ��ļ���ʽ ��[".jpg","gif"]</param>
        /// <param name="allowExtensions">�ļ��ϴ���С���ƣ���λΪM��Ϊnull��Ĭ��</param>
        /// <param name="allowExtensions">��֤������Ϣ</param>
        /// <returns></returns>
        public static bool CheckFileType(HttpFileCollection files, string controlName, string[] allowExtensions, int? fileSize, out string msg)
        {
            bool fileAllow = false;
            msg = "";
            if (fileSize == null) { fileSize = 5; };
            if (files != null && files.Count > 0)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    if (files.GetKey(i).ToString() == controlName)
                    {
                        if (files[i] != null && files[i].FileName.Trim() == "")
                        {
                            return true;
                        }

                        if (files[i].ContentLength / 1024 / 1024 > fileSize)
                        {
                            msg = files[i].FileName + " �ļ������޷��ϴ�!";
                            return false;
                        }
                        string fileExtension = System.IO.Path.GetExtension(files[i].FileName).ToLower();
                        for (int j = 0; j < allowExtensions.Length; j++)
                        {
                            if (fileExtension.ToLower() == allowExtensions[j].ToLower())
                            {
                                fileAllow = true;
                            }
                        }
                    }
                }
            }
            if (!fileAllow)
            {
                msg = "�ļ���ʽ����ȷ!";
            }
            else
            {
                msg = "��֤�ɹ�!";
            }
            return fileAllow;
        }
Beispiel #3
0
 public override string GetKey(int index)
 {
     return(w.GetKey(index));
 }
    /// <summary>
    /// 获取并上传附件
    /// </summary>
    public void UpFileData()
    {
        string strNewAttachIds = string.Empty;
        string dataField       = Request.Form["dataField"];
        string instanceID      = Request.Form["InstanceID"] + string.Empty;
        //新加的属性,待确认
        //ERROR:
        string schemaCode  = Request.Form["SchemaCode"] + string.Empty;
        string bizObjectID = Request.Form["BizObjectID"] + string.Empty;

        //string workflowPackage = Request.Form["WorkflowPackage"] + string.Empty;
        //string workflowName = Request.Form["WorkflowName"] + string.Empty;
        if (dataField == string.Empty)
        {
            return;
        }
        System.Web.HttpPostedFile theFile;
        //说明:若控件的参数 <PARAM NAME="DelFileField" VALUE="DELETE_FILE_NAMES">
        //则,从Request.Form得到的DELETE_FILE_NAMES集合包含了所有需要删除的文件
        //也就是客户端修改过的文件名
        string[] delFileNames = Request.Form.GetValues("DELETE_FILE_NAMES");
        System.Web.HttpFileCollection uploadFiles = Request.Files;

        try
        {
            OThinker.H3.Data.AttachmentHeader[] headers = null;
            if (instanceID != string.Empty)
            {
                headers = OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.QueryAttachment(schemaCode, bizObjectID, dataField, OThinker.Data.BoolMatchValue.True, string.Empty);
            }

            // 增加保存附件文件
            for (int i = 0; i < uploadFiles.Count; i++)
            {
                theFile = uploadFiles[i];
                // "EDITFILE"和客户端的BeginSaveToURL的第二个参数一致
                if (uploadFiles.GetKey(i).ToUpper() == "EDITFILE")
                {
                    // 写入FILE数据
                    string fname       = theFile.FileName;
                    int    fsize       = theFile.ContentLength;
                    string contentType = theFile.ContentType;
                    byte[] buffer      = new byte[theFile.ContentLength];
                    theFile.InputStream.Read(buffer, 0, fsize);

                    OThinker.H3.Data.Attachment attachment = new OThinker.H3.Data.Attachment()
                    {
                        ObjectID            = Guid.NewGuid().ToString(),
                        FileName            = fname,
                        ContentType         = string.Empty,
                        Content             = buffer,
                        DataField           = HttpUtility.UrlDecode(dataField),
                        CreatedBy           = OThinker.Organization.User.AdministratorID,
                        Downloadable        = true,
                        BizObjectId         = bizObjectID,
                        BizObjectSchemaCode = schemaCode
                    };

                    strNewAttachIds += attachment.ObjectID + ",";

                    OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.AddAttachment(attachment);
                }
            }
            if (headers != null && delFileNames != null)
            {
                foreach (OThinker.H3.Data.AttachmentHeader header in headers)
                {
                    if (Array.IndexOf <string>(delFileNames, header.FileName) > -1)
                    {
                        OThinker.H3.Controllers.AppUtility.Engine.BizObjectManager.RemoveAttachment(OThinker.Organization.User.AdministratorID,
                                                                                                    schemaCode,
                                                                                                    header.BizObjectId,
                                                                                                    header.ObjectID);
                    }
                }
            }
            Response.Write(strNewAttachIds);
        }
        catch (Exception err)
        {
            OThinker.H3.Controllers.AppUtility.Engine.LogWriter.Write("NTKO Attachment ERROR:" + err.ToString());
        }
    }
Beispiel #5
0
        /// <summary>
        /// ���ļ��ϴ�
        /// </summary>
        /// <param name="files">Request.Files ����</param>
        /// <param name="controlName">�ϴ��ؼ���name ֵ</param>
        /// <param name="folderName">�ļ��ϴ����ļ�����</param>
        /// <param name="filePath">�����ļ��Ĵ洢����·������</param>
        /// <returns></returns>
        public static bool FileUpLoad(HttpFileCollection files, string controlName, string folderName, out IList<string> filePath)
        {
            filePath = new List<string>();
            if (files != null && files.Count > 0)
            {
                for (int i = 0; i < files.Count; i++)
                {
                    if (files.GetKey(i).ToString().ToUpper() == controlName.ToUpper())
                    {
                        string path = "/uploadFiles/" + folderName + "/" + (GetTimeRandom() + Path.GetExtension(files[i].FileName));
                        filePath.Add(path);

                        try
                        {
                            files[i].SaveAs(System.Web.HttpContext.Current.Server.MapPath(path));
                        }
                        catch
                        {
                            return false;
                        }

                    }

                }
            }
            return true;
        }
 public override string GetKey(int index)
 {
     return(_collection.GetKey(index));
 }