| C# |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Для добавления внешних файлов в ресурс следует добавить файл в проект и установить его
свойство Build Action в Embedded Resource. После чего доступ к нему можно получить следующим образом:
System.IO.Stream st =
System.Reflection.Assembly.
GetExecutingAssembly().
GetManifestResourceStream("Veb.Editors.search.txt");
System.IO.StreamReader sr =
new System.IO.StreamReader( st,
System.Text.Encoding.GetEncoding(1251));
string s = sr.ReadToEnd();
sr.Close();
|
|
|
|
|
|
|
|
|
|
|
Помещаем объект в Cache
Cache.Insert ("Cachename" + Variable, Source, null, DateTime.Now.AddDays(1), TimeSpan.Zero);
Извлекаем
string CustomCache = Cache.Get("CustomCache" + Variable);
if (CustomCache == null){ //Check to see if cache already exists
//'... Your object gets inserted into the cache
} else {
//Read your data from the cache
YourDatasource or DataOutput = CustomCache;
}
|
|
|
|
|
|
|
string sFileName = @"d:\work\test\pic_1."; int iScale = 10; // Читаем из файла System.Drawing.Bitmap oldImg = new System.Drawing.Bitmap(sFileName+"bmp"); // Создаем в памяти пустышку System.Drawing.Bitmap newImg = new System.Drawing.Bitmap(oldImg.Width/iScale,oldImg.Height/iScale); // Отрисовываем там масштабированную картинку System.Drawing.Graphics gr = System.Drawing.Graphics.FromImage(newImg); System.Drawing.Rectangle rc = new System.Drawing.Rectangle(0,0,newImg.Width,newImg.Height); gr.DrawImage(oldImg,rc,0,0,oldImg.Width,oldImg.Height,System.Drawing.GraphicsUnit.Pixel); // Сохраняем результат newImg.Save(sFileName+"jpg",System.Drawing.Imaging.ImageFormat.Jpeg); // Освобождаем ресурсы oldImg.Dispose(); newImg.Dispose(); gr.Dispose(); |
|
|
Bitmap objBitmap = new Bitmap(120,30);
Graphics objGraphics = Graphics.FromImage(objBitmap); //Fill the background
objGraphics.FillRectangle(new SolidBrush(Color.LightBlue),0,0,120,30);
//Create blue-yellow bullet point
objGraphics.FillEllipse(new SolidBrush(Color.Blue),3,9,10,10);
objGraphics.FillEllipse(new SolidBrush(Color.Yellow),4,10,8,8);
//Draw text next to bullet point
objGraphics.DrawString("Submit", new Font("Tahoma",8), new SolidBrush(Color.Green), 16,8);
//Render Page.Response.Clear();
Page.Response.ContentType = "image/jpeg";
objBitmap.Save(Page.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
//Tidy up
objGraphics.Dispose();
objBitmap.Dispose();
|
|
|
|
|
|
|
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Public Class DataRelation
Inherits System.Web.UI.Page
Protected lblDisplay As System.Web.UI.WebControls.Label
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim objConn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim dtrParent As DataRow
Dim dtrChild As DataRow
objConn = New SqlConnection(ConfigurationSettings.Appsettings("NorthwindConnection"))
da = New SqlDataAdapter("SELECT * FROM Categories", objConn)
ds = New DataSet()
Try
objConn.Open()
da.Fill( ds,"Categories")
da.SelectCommand = New SqlCommand("SELECT * FROM Products", objConn)
da.Fill(ds, "Products")
Catch exc As SqlException
Response.Write(exc.ToString())
Finally
objConn.Dispose()
End Try
|
'Create the Data Relationship
ds.Relations.Add("Cat_Prod",ds.Tables("Categories").Columns("CategoryID"), _
ds.Tables("Products").Columns("CategoryID"))
'Display the Category and Child Products Within
For each dtrParent in ds.Tables("Categories").Rows
lblDisplay.Text &= "<h3>" & dtrParent("CategoryName") & "</h3><ul>"
For each dtrChild in dtrParent.GetChildRows("Cat_Prod")
lblDisplay.Text &= "<li>" & dtrChild("ProductName") & "</li>"
Next
lblDisplay.Text &= "</ul>"
Next
End Sub
End Class
|
|
|
Все классы .NET можно сделать видимыми как СОМ-объекты. Для этого нужно:
|
|
|
Environment.MachineName Environment.UserName |
|
|
|
|