Пример #1
0
        public static void DownloadFile(string path)
        {
            try
            {
                Settings.RelativePath = path = path.Replace(Devider, Path.DirectorySeparatorChar);

                var last = path.Split(Path.DirectorySeparatorChar).Last();

                Settings.RelativePath = path.Substring(0, path.Length - last.Length);

                var folder = new Folder("");
                var file   = new File(last);
                folder.Add(file);

                var fileName = file.Name;
                var data     = file.GetData();

                HttpContext.Current.Response.AddHeader("Content-disposition", "attachment;filename=" + fileName);
                HttpContext.Current.Response.ContentType = "application/octet-stream";
                HttpContext.Current.Response.BinaryWrite(data);

                HttpContext.Current.Response.Flush();
                HttpContext.Current.Response.Close();
                HttpContext.Current.Response.End();
            }
            catch (Exception ex)
            {
                // ignored
            }
        }
Пример #2
0
        public static string UploadFile(string path, string fileName, string based64BinaryString)
        {
            var base64 = "base64,";
            var idx    = based64BinaryString.IndexOf(base64, StringComparison.Ordinal);
            var str    = based64BinaryString.Substring(idx + base64.Length);

            var data = Convert.FromBase64String(str);

            Settings.RelativePath = path = path.Replace(Devider, Path.DirectorySeparatorChar);

            var last = path.Split(Path.DirectorySeparatorChar).Last();

            Settings.RelativePath = path.Substring(0, path.Length - last.Length);

            var folder = new Folder(last);
            var file   = new File(fileName);

            folder.Add(file);

            file.SetData(data);

            return("ok");
        }