Unable to save .bmp image to server from ASP.NET

crzyvirus

New Member
In an ASP.net (C#) web app I have created a signature pad using HTML 5 canvas and java script. We are capturing the signature with touch devices (android and iOS).When the signature is completed it sends the data from the canvas to the server where I convert it to a .bmp image and save it to a directory called signature files on the root program directory on the server using Bitmap.Save(location, Format). This has been working fine for several clients for many months until now. Unfortunately I am currently catching exceptions but not sending them anywhere (huge mistake that I am currently working on rectifying). If I have to I will recompile the code with some exception outputs so that I can get more information but since its a new client I would love to be able to fix this asap and since the code has been working for a long time without issue, I'm optimistic that its a server setting.Is there a security setting in IIS7 or Windows Server 2008 that may be blocking the app from saving a file to the server. If not is there something that may need to be installed on the server to allow the following:\[code\]byte[] imageBytes = Convert.FromBase64String(suffix);MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);ms.Write(imageBytes, 0, imageBytes.Length);string thePath = Path.GetDirectoryName(saveLocation);FileStream fs = new FileStream(thePath + @"\image.png", FileMode.Create);BinaryWriter bw = new BinaryWriter(fs);bw.Write(imageBytes);bw.Close(); if (string.IsNullOrEmpty(Path.GetFileName(saveLocation))) { string filename = Path.GetRandomFileName(); filename = filename.Substring(0, filename.IndexOf('.')); filename = filename + Path.GetRandomFileName(); filename = filename.Substring(0, filename.IndexOf('.')); theSaveLocation = saveLocation + @"\" + filename + "." + format; } ms = new MemoryStream(); Bitmap input = (Bitmap)Bitmap.FromFile(thePath + @"\image.png"); Bitmap result = ProcessBitmap(input, Color.White); result = (Bitmap)resizeImage((System.Drawing.Image)result, size); result.Save(theSaveLocation, System.Drawing.Imaging.ImageFormat.Bmp); input.Dispose(); result.Dispose(); ms.Close();\[/code\]Here's the process Bitmap function that I used above\[code\]private Bitmap ProcessBitmap(Bitmap bitmap, Color color){ Bitmap temp = new Bitmap(bitmap.Width, bitmap.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb); Graphics g = Graphics.FromImage(temp); g.Clear(color); g.DrawImage(bitmap, Point.Empty); return temp;}\[/code\]Here's the resizeImage function that I used above:\[code\]private static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size){ int sourceWidth = imgToResize.Width; int sourceHeight = imgToResize.Height; float nPercent = 0; float nPercentW = 0; float nPercentH = 0; nPercentW = ((float)size.Width / (float)sourceWidth); nPercentH = ((float)size.Height / (float)sourceHeight); if (nPercentH < nPercentW) nPercent = nPercentH; else nPercent = nPercentW; int destWidth = (int)(sourceWidth * nPercent); int destHeight = (int)(sourceHeight * nPercent); Bitmap b = new Bitmap(destWidth, destHeight); Graphics g = Graphics.FromImage((System.Drawing.Image)b); g.DrawImage(imgToResize, 0, 0, destWidth, destHeight); g.Dispose(); return (System.Drawing.Image)b;}\[/code\]
 
Back
Top