Example #1
0
        public FileWriteResponse WriteFileToDisk(byte[] fileByteArray, string fileName)
        {
            FileWriteResponse response = new FileWriteResponse();

            try
            {
                if (!FileExist(fileName))
                {
                    var    pathLocation = HttpContext.Current.Server.MapPath(Utils.GetAppSettings.GetAttachmentDirectoryPath());
                    string fileLocation = Path.Combine(pathLocation, fileName);
                    using (var fs = new FileStream(fileLocation, FileMode.Create, FileAccess.ReadWrite))
                    {
                        fs.Write(fileByteArray, 0, fileByteArray.Length);
                        // Set the stream position to the beginning of the file.
                        fs.Seek(0, SeekOrigin.Begin);
                    }


                    response.Text = "File uploaded successfull!";
                }
                else
                {
                    throw new Exception("File already  exist!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("File can not be uploaded!");
            }

            return(response);
        }
Example #2
0
        public FileWriteResponse WriteFileToDisk(string fileBase64, string fileName)
        {
            FileWriteResponse response = new FileWriteResponse();

            try
            {
                if (!FileExist(fileName))
                {
                    var    pathLocation = HttpContext.Current.Server.MapPath(Utils.GetAppSettings.GetAttachmentDirectoryPath());
                    string fileLocation = Path.Combine(pathLocation, fileName);
                    //fileBase64 = fileBase64.Substring(fileBase64.IndexOf(",") + 1);
                    File.WriteAllBytes(fileLocation, Convert.FromBase64String(fileBase64));


                    response.Text = "File uploaded successfull!";
                }
                else
                {
                    throw new Exception("File already  exist!");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("File can not be uploaded!");
            }

            return(response);
        }