Wednesday, December 29, 2010
Store Data in Special Folder in system
LogFile = LogFile +
{
}
string LogFile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);"\\Log.txt";if(!File.Exists(LogFile))File.WriteAllText(LogFile, "Hi There");else{
}string Data=File.ReadAllText(LogFile);
Monday, December 27, 2010
Open memoryStream in Browser
"_wb.DocumentStream = _originalDocStream;"
where wb is the object of webrowser.
and originalDocStream is memorystream
where wb is the object of webrowser.
and originalDocStream is memorystream
Code to Check filte Type by reading its Content
public bool isPDFDocument(string file)
{
string mimeout = "";
int MaxContent = 0;
Stream fs = null;
byte[] buf = null;
int result = 0;
try
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(file);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
fs = response.GetResponseStream();
//MaxContent = response.ContentLength;
if (response.ContentLength > 4096)
{
MaxContent = 4096;
}
else
{
MaxContent =
Convert.ToInt32(response.ContentLength);
}
buf =
new byte[MaxContent + 1];
fs.Read(buf, 0, MaxContent);
fs.Close();
result = FindMimeFromData(
IntPtr.Zero, null, buf, MaxContent, null, 0, ref mimeout, 0);
if (mimeout != null && (mimeout.ToLower().Contains("pdf" ) || mimeout.ToLower().Contains("tif" )))
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
{
string mimeout = "";
int MaxContent = 0;
Stream fs = null;
byte[] buf = null;
int result = 0;
try
{
HttpWebRequest request = (HttpWebRequest)
WebRequest.Create(file);
HttpWebResponse response = (HttpWebResponse)
request.GetResponse();
fs = response.GetResponseStream();
//MaxContent = response.ContentLength;
if (response.ContentLength > 4096)
{
MaxContent = 4096;
}
else
{
MaxContent =
Convert.ToInt32(response.
}
buf =
new byte[MaxContent + 1];
fs.Read(buf, 0, MaxContent);
fs.Close();
result = FindMimeFromData(
IntPtr.Zero, null, buf, MaxContent, null, 0, ref mimeout, 0);
if (mimeout != null && (mimeout.ToLower().Contains("
{
return true;
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
}
Copy filters for RadGridView to RadChart in Silverlight
void RadGridView1_Filtered(object sender, GridViewFilteredEventArgs e)
{
RadChart1.FilterDescriptors.Clear();
{
RadChart1.FilterDescriptors.
foreach (IFilterDescriptor Filter in RadGridView1.FilterDescriptors)
{
RadChart1.FilterDescriptors.Add(Filter);
}
}
{
RadChart1.FilterDescriptors.
}
}
Fetch and display columns from MYSQL DB
public void FetchData()
{
List<string> ColumnNames = new List<string>();
string MyConString = ConfigurationManager.ConnectionStrings["conRadBoard"].ToString();
OdbcConnection MyConnection = new OdbcConnection(MyConString);
try
{
MyConnection.Open();
OdbcCommand MyCommand =
new OdbcCommand("show Columns from employee_data", MyConnection);
OdbcDataAdapter ad = new OdbcDataAdapter(MyCommand);
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (dr["Field"] != null)
{
ColumnNames.Add(dr["Field"].ToString());
}
}
}
string sqlstr="Select ";
int x = ColumnNames.Count;
foreach (string s in ColumnNames)
{
if (s != string.Empty)
{
sqlstr += s;
x--;
}
if(x>0)
{
sqlstr += ",";
}
}
ds.Clear();
sqlstr += " from employee_data";
MyCommand.Parameters.Clear();
MyCommand = new OdbcCommand(sqlstr,MyConnection);
ad = new OdbcDataAdapter(MyCommand);
ds = new DataSet();
ad.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
MyConnection.Close();
}
}
IValue Convertor for radgrid view silverlight Telerik
| public class | ||||||||||||
| { | ||||||||||||
| public object | ||||||||||||
| { | ||||||||||||
| Int64 num; | ||||||||||||
| if( Int64. | ||||||||||||
| return | ||||||||||||
| else | ||||||||||||
| return | ||||||||||||
| } | ||||||||||||
| public object | ||||||||||||
| { | ||||||||||||
| throw new | ||||||||||||
| } | ||||||||||||
}
|
Download and display images from http path in silverlight
WebClient downloader = new WebClient();
public Page()
{
InitializeComponent();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
// Display an image from a package.
//StreamResourceInfo photosDownloaded = new StreamResourceInfo(e.Result as
Stream, null);
//string photoToGrab = e.UserState.ToString();
//StreamResourceInfo photoStream = Application.GetResourceStream(photosDownloaded,
new Uri(photoToGrab, UriKind.Relative));
//BitmapImage bitmap = new BitmapImage();
//bitmap.SetSource(photoStream.Stream);
//bitmap.SetSource(e.Result);
//imgPhoto.Source = bitmap;
// Display a single image.
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.Result);
imgPhoto.Source = bitmap;
}
private void dgAthleteList_SelectionChanged(object sender, EventArgs e)
{
AthleteDisplayInfo athlete = (AthleteDisplayInfo)dgAthleteList.SelectedItem;
// verify that an athlete is selected.
if (athlete != null)
{
txtFirstName.Text = athlete.FirstName;
txtLastName.Text = athlete.LastName;
// download a package.
// downloader.OpenReadAsync(new Uri("Photos/Photos.zip", UriKind.Relative),
athlete.AthleteId.ToString() + ".JPG");
// download a single file.
downloader.OpenReadAsync(new Uri("Photos/" + athlete.AthleteId.ToString() +
".JPG", UriKind.Relative));
}
public Page()
{
InitializeComponent();
downloader.OpenReadCompleted += new OpenReadCompletedEventHandler(downloader_OpenReadCompleted);
}
void downloader_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
// Display an image from a package.
//StreamResourceInfo photosDownloaded = new StreamResourceInfo(e.Result as
Stream, null);
//string photoToGrab = e.UserState.ToString();
//StreamResourceInfo photoStream = Application.GetResourceStream(photosDownloaded,
new Uri(photoToGrab, UriKind.Relative));
//BitmapImage bitmap = new BitmapImage();
//bitmap.SetSource(photoStream.Stream);
//bitmap.SetSource(e.Result);
//imgPhoto.Source = bitmap;
// Display a single image.
BitmapImage bitmap = new BitmapImage();
bitmap.SetSource(e.Result);
imgPhoto.Source = bitmap;
}
private void dgAthleteList_SelectionChanged(object sender, EventArgs e)
{
AthleteDisplayInfo athlete = (AthleteDisplayInfo)dgAthleteList.SelectedItem;
// verify that an athlete is selected.
if (athlete != null)
{
txtFirstName.Text = athlete.FirstName;
txtLastName.Text = athlete.LastName;
// download a package.
// downloader.OpenReadAsync(new Uri("Photos/Photos.zip", UriKind.Relative),
athlete.AthleteId.ToString() + ".JPG");
// download a single file.
downloader.OpenReadAsync(new Uri("Photos/" + athlete.AthleteId.ToString() +
".JPG", UriKind.Relative));
}
Filter XML from XELement in Silverlight
XElement rss = XElement.Load(sr); s =
new XElement("NewDataSet",
from table in rss.Elements("Table")
select new XElement("Table", table.Elements()
)
);
filterCategory =
new XElement("NewDataSet",
from table in rss.Elements("Table")
where (string)table.Element("PDF_NAME" ) == "Shiley_Quick_Reference_Guide.pdf"
select new XElement("Table", table.Elements()
)
);
new XElement("NewDataSet",
from table in rss.Elements("Table")
select new XElement("Table", table.Elements()
)
);
filterCategory =
new XElement("NewDataSet",
from table in rss.Elements("Table")
where (string)table.Element("PDF_
select new XElement("Table", table.Elements()
)
);
Convert Stream into MemoryStream
using (MemoryStream ms = new MemoryStream())
{
int bytes = 0;
byte[] temp = new byte[4096];
while ((bytes = s.Read(temp, 0, temp.Length)) 0)
ms.Write(temp, 0, bytes);
Response.BinaryWrite(ms.ToArray());
}
{
int bytes = 0;
byte[] temp = new byte[4096];
while ((bytes = s.Read(temp, 0, temp.Length)) 0)
ms.Write(temp, 0, bytes);
Response.BinaryWrite(ms.
}
Subscribe to:
Comments (Atom)