Exemplo n.º 1
0
        public static bool SaveFileBase64(string folder, string filename, string strBase64)
        {
            //data:image/gif;base64,
            //this image is a single pixel (black)
            try
            {
                string webFolder = SWCmsHelper.GetFullPath(new string[]
                {
                    SWCmsConstants.Parameters.WebRootPath,
                    folder
                });
                string fullPath = SWCmsHelper.GetFullPath(new string[]
                {
                    webFolder,
                    filename
                });
                string fileData = strBase64.Substring(strBase64.IndexOf(',') + 1);
                byte[] bytes    = Convert.FromBase64String(fileData);

                if (!Directory.Exists(webFolder))
                {
                    Directory.CreateDirectory(webFolder);
                }

                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                }

                FileStream   fs = new FileStream(fullPath, FileMode.Create);
                BinaryWriter w  = new BinaryWriter(fs);
                try
                {
                    w.Write(bytes);
                }
                finally
                {
                    fs.Close();
                    w.Close();
                }
                return(true);
            }
            catch//(Exception ex)
            {
                return(false);
            }
        }
Exemplo n.º 2
0
        public static bool RemoveFile(string filePath)
        {
            bool result = false;

            try
            {
                string fullPath = SWCmsHelper.GetFullPath(new string[]
                {
                    SWCmsConstants.Parameters.WebRootPath,
                    filePath
                });
                if (File.Exists(fullPath))
                {
                    File.Delete(fullPath);
                    result = true;
                }
            }
            catch
            {
            }
            return(result);
        }