Example #1
0
        // this is another test not with httpclient, but with HttpWebRequest
        public bool UploadFileHttpWebRequest(string fileFullPath, CUserInfo user)
        {
            CUploadFile cUploadFile = new CUploadFile();
            bool        uploaded    = cUploadFile.SendFile(client.BaseAddress.AbsoluteUri + "api/file/UploadAsync", fileFullPath);

            return(uploaded);
        }
Example #2
0
        public void GetFileDownload(int downloadIndex)
        {
            var uUploadFile = new CUploadFile();
            var fileList    = uUploadFile.GetUploadFiles(UploadType, downloadIndex);

            RadListBoxFileInfo.Items.Clear();
            foreach (var file in fileList)
            {
                RadListBoxFileInfo.Items.Add(new RadListBoxItem(file.Name, file.UploadFileId.ToString()));
            }
        }
Example #3
0
    /// <summary>
    /// </summary>
    /// <param name="uploadFileId"></param>
    public void DownloadFile(int uploadFileId)
    {
        var cUploadFile = new CUploadFile();
        var uploadFile  = cUploadFile.Get(uploadFileId);
        var fullPath    = Path.Combine(CConstValue.WebUploadPath, uploadFile.Path, uploadFile.Name);

        try
        {
            Response.Clear();
            // Clear the content of the response
            Response.ClearContent();
            Response.ClearHeaders();
            // Buffer response so that page is sent
            // after processing is complete.
            Response.BufferOutput = true;
            // Add the file name and attachment,
            // which will force the open/cance/save dialog to show, to the header

            var oFile    = new FileInfo(fullPath);
            var fileName = oFile.Name;

            if (File.Exists(fullPath))
            {
                Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);

                Response.ContentType = "application/octet-stream";
                Response.WriteFile(fullPath);

                Response.Flush();

                HttpContext.Current.ApplicationInstance.CompleteRequest();
                //Response.End();
            }
            else
            {
                if (Request.UrlReferrer != null)
                {
                    var csType   = GetType();
                    var jsScript = "alert('File Not Found');";
                    ScriptManager.RegisterClientScriptBlock(Page, csType, "popup", jsScript, true);
                }
            }
        }
        catch (Exception ex)
        {
            Debug.Print(ex.Message);
        }
    }
Example #4
0
        public void SaveFile(int newIndex)
        {
            // delete list of hidden files in listbox
            var cUploadFile = new CUploadFile();

            foreach (RadListBoxItem item in RadListBoxFileInfo.Items)
            {
                if (item.Enabled == false)
                {
                    cUploadFile.DelUploadFile(Convert.ToInt32(item.Value));
                }
            }

            // upload on basepage
            ((PageBase)Page).UploadFiles(AsyncUpload, UploadType, newIndex);
        }
Example #5
0
    /// <summary>
    /// </summary>
    /// <param name="asyncUpload">asyncUpload control</param>
    /// <param name="approveType">menu type</param>
    /// <param name="seqId">db seq</param>
    public void UploadFiles(RadAsyncUpload asyncUpload, int approveType, int seqId)
    {
        foreach (UploadedFile uploadedFile in asyncUpload.UploadedFiles)
        {
            var upType = approveType.ToString();
            var upSeq  = seqId.ToString();

            // Server.MapPath("~/Upload/");
            var pathType = Path.Combine(CConstValue.WebUploadPath, upType);
            var pathSeq  = Path.Combine(pathType, upSeq);

            if (!Directory.Exists(pathType))
            {
                Directory.CreateDirectory(pathType);
                Directory.CreateDirectory(pathSeq);
            }
            else if (!Directory.Exists(pathSeq))
            {
                Directory.CreateDirectory(pathSeq);
            }

            asyncUpload.TargetFolder = upType + @"\" + upSeq + @"\";

            var fileName = DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + "_" + DateTime.Now.ToString("hhmmss") + "_" + uploadedFile.FileName;

            uploadedFile.SaveAs(Path.Combine(pathSeq, fileName));


            var cFile = new CUploadFile();
            var file  = new UploadFile();
            file.UploadType = Convert.ToInt32(upType);
            file.SeqId      = Convert.ToInt32(upSeq);
            file.Path       = asyncUpload.TargetFolder;
            file.Name       = fileName;

            file.CreatedId   = CurrentUserId;
            file.CreatedDate = DateTime.Now;
            file.UpdatedId   = CurrentUserId;
            file.UpdatedDate = DateTime.Now;

            if (cFile.Add(file) > 0)
            {
            }
        }
    }