Skip to main content

Posts

Showing posts with the label C#

A generic error occurred in GDI+ while creating image from Base64 string

In a web service, while converting a Base64 string to file, it is sometimes giving error  - "A generic error occurred in GDI+ while creating image from Base64 string". Solution: I have used the below code and problem resolved. [ HttpPost] public ActionResult UploadSignatureTwo(String imageString){          var bytes = Convert.FromBase64String(imageString);      using (var imageFile = new FileStream(Path.Combine(path,"test.jpeg"), FileMode.Create))      {          imageFile.Write(bytes, 0, bytes.Length);          imageFile.Flush();      } }

file upload not working in updatepanel asp.net

The Fileupload Control is not working in the UpdatePanel in asp.net. To use the FileUpload control in the Updatepanel. We need to add the Post back trigger to the UpdatePanel Like the below Code < asp : UpdatePanel ID = "UpnlFileUpload" runat = "server" > < ContentTemplate > < asp : FileUpload ID = "FlUpload" runat = "server" /> < asp : Button ID = "btnFileUpload" runat = "server" Text = "Upload" OnClick = "btnFileUpload_OnClick" /> </ ContentTemplate > < Triggers > < asp : PostBackTrigger ControlID = "btnFileUpload" /> </ Triggers > </ asp : UpdatePanel > Here we need to pass the Button Control ID in the PostBackTrigger Like the above code. Generally after adding the PostBackTrigger it works accurate but some time it will not work. In this case you need to add the below code in the  Page_Lo...

C# - Copy DataTable from one DataSet to another

When we trying to add a DataTable (that is inside of a different DataSet) to new DataSet ds. If I add it directly, we will get the following error:                     DataTable already belongs to another DataSet. DataTable.Copy use DataTable.Copy to create a copy of your data table; then insert the copy into the target DataSet: dataSetX.Tables.Add( dataTableFromDataSetY.Table[0].Copy() ); DataSet.Merge You could also use DataSet.Merge for this: dataSetX.Merge(dataTableFromDataSetY); Note, however, that if you are going to use this method, you might want to make sure that your target DataSet doesn't already contain a table with the same name: If the target DataSet doesn't contain a table by the same name, a fresh copy of the table is created inside the data set; If a table by the same name is already in the target data set, then it will get merged with the one passed to Merge, and you end up with a mix of the two.

Upload Multiple Files Using FileUpload Control In ASP.NET 4.5 +

ASP.NET 4.5 and upper versions support this feature. Now, FileUpload  control is built to support HTML 5, therefore it is only supported in browsers supporting HTML5. For other browsers it will work like a normal file upload control in ASP.NET. A new Attribute introduces with the ASP.NET 4.5 FileUplaod control i.e.  AllowMultiple ,  It takes either true or false. In order to support multiple file uploads, set AllowMulitple =" true " other than false. < asp:FileUpload   runat = "server"   ID = "UploadImages"   AllowMultiple = "true"  /> In addition to this control, some new properties have been included to support code-behind coding. HasFiles Check whether FileUpload control has multiple files or not. PostedFiles Basically used to get all the files from the FileUpload control in the iteration. Example code to upload files:    < asp:FileUpload runat ="server" ID ="UploadImages" AllowMultiple ="t...

What is the difference between smalldatetime and datetime?

DateTime SmallDateTime Storage Size 8 Bytes 4 Bytes FORMAT YYYY-MM-DD hh:mm:ss.nnn YYYY-MM-DD hh:mm:ss MIN Value 1753-01-01 00:00:00 1900-01-01 00:00:00 MAX Value 9999-12-31 23:59:59.997 2079-06-06 23:59:00 Accuracy Rounded to increments of .000, .003, or .007 second It means: If time part in the date is 23:59:58.990 or 23:59:58.991, it will be stored as 23:59:58.990. 1 Minute Second’s values that are 29.998 seconds or less are rounded down to the nearest minute. And second’s values of 29.999 seconds or more are rounded up to the nearest minute. So seconds part value is always 00.

C#, Read a file

C#, Code to read a file  String strHtmlMessage = String .Empty; String strFilePath = HttpContext.Current.Server.MapPath("~/Mails/Confirmationmaill.htm");   using (StreamReader sr = new StreamReader(strFilePath))   {     strHtmlMessage = sr.ReadToEnd();  }