Code Snippets - ASP.NET, C#, JAVA, Android. Tutorials, Code Snippets, Bug Fixing etc
![]() |
| Hostgator Offers |
public static bool HasNull(this DataTable table)
{
foreach (DataColumn column in table.Columns)
{
if (table.Rows.OfType<DataRow>().Any(r => r.IsNull(column)))
return true;
}
return false;
}
and use
table.HasNull();
DBNull.Value value to filter and manage null values in whatever way you see fit.
foreach(DataRow row in table.Rows)
{
object value = row["ColumnName"];
if (value == DBNull.Value)
// do something
else
// do something else
}
Check More About DBNull Class
![]() |
| Get 25% Off on HostGator Hosting Coupon Code |
string file = Server.MapPath ("abc.html");
StreamReader sr;
FileInfo fi = new FileInfo(file);
if(File.Exists(file))
{
sr = File.OpenText(file);
input += sr.ReadToEnd();
sr.Close();
}
string[] lines = File.ReadAllLines("path/to/my/file.html");
foreach(string line in lines)
{
Response.Write(line);
}
DateTime dt = DateTime.ParseExact(dr["dateCreated"].ToString().Trim(),
"M/d/yyyy h:mm:ss tt", CultureInfo.InvariantCulture);
//dr["dateCreated"] returnsdate from database
DateTime date4;
string dateString = @"20/05/2012";
bool result = DateTime.TryParse(dateString,out date4);
the parsing fails, but it will not throw error, rather it returns
falseindicating that theparsing failed.
string dateString = @"20/05/2012";
DateTime date2 = Convert.ToDateTime(dateString,
System.Globalization.CultureInfo.GetCultureInfo("hi-IN").DateTimeFormat);
In Web.config under <configuration> Tag
<connectionStrings>
<add name="ConnStringDb1" connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
in C# code usage
SqlCommand command; public static string connectionstring = ConfigurationManager.ConnectionStrings["ConnStringDb1"].ToString(); SqlConnection conn = new SqlConnection(connectionstring);
Dont Forget to add "using System.Configuration;"
byte[] imageData = DownloadData(Url); //Url is image link MemoryStream stream = new MemoryStream(imageData); Image img = Image.FromStream(stream); stream.Close();
string saveImagePath = System.Web.HttpContext.Current.Server.MapPath("../media/full/") + "image.jpg";
img.Save(saveImagePath, System.Drawing.Imaging.ImageFormat.Jpeg);private static void SetPermissions(string dirPath){ DirectoryInfo info = new DirectoryInfo(dirPath); WindowsIdentity self = System.Security.Principal.WindowsIdentity.GetCurrent(); DirectorySecurity ds = info.GetAccessControl(); ds.AddAccessRule(new FileSystemAccessRule(self.Name, FileSystemRights.FullControl, InheritanceFlags.ObjectInherit | InheritanceFlags.ContainerInherit, PropagationFlags.None, AccessControlType.Allow)); info.SetAccessControl(ds);}
read-only on access on fileFileInfo myFile = new FileInfo(files.FullName);myFile.IsReadOnly = false;public string ImageToBase64(Image image, System.Drawing.Imaging.ImageFormat format) { using (MemoryStream ms = new MemoryStream()) { // Convert Image to byte[] image.Save(ms, format); byte[] imageBytes = ms.ToArray(); // Convert byte[] to Base64 String string base64String = Convert.ToBase64String(imageBytes); return base64String; } }
public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length); Image image = Image.FromStream(ms, true); return image; }
Copyright @ 2013 Code Snippets.