コード例 #1
0
        public string Upload(HttpPostedFileBase fileData, string id)
        {
            string m_return = "ok";

            try
            {
                if (fileData != null && fileData.ContentLength > 0)
                {
                    Guid fileId = Guid.NewGuid();

                    var extension = Path.GetExtension(fileData.FileName);

                    var filePath = string.Format("/Content/uploads/{0}", Path.GetFileName(fileId.ToString() + extension));

                    var filePost = Path.Combine(AppDomain.CurrentDomain.BaseDirectory + filePath);

                    //var filePost = this.Server.MapPath(filePath);

                    string[] words     = id.Split(';');
                    var      sessionid = words[0];

                    FileUpload model = new FileUpload {
                        kFileUploadId = fileId,
                        kSessionId    = new Guid(sessionid),
                        sFileUrl      = filePath
                    };
                    fileData.SaveAs(filePost);
                    FileUploadManager.Create(model);
                }
            }
            catch (Exception ex)
            {
                m_return = ex.Message;
            }
            return(m_return);
        }