posts - 305,comments - 157,trackbacks - 10

http://www.cnblogs.com/birdshover/archive/2008/08/26/1277103.html

 

http://www.cnblogs.com/focustea/archive/2009/07/07/1518484.html 

posted @ 2010-05-25 14:00 冷火 阅读(45) 评论(0) 编辑
using System.IO;
using Argotic.Syndication;

RssFeed feed = new RssFeed();

feed.Channel.Link = new Uri("http://localhost");
feed.Channel.Title = "Simple RSS Feed";
feed.Channel.Description = "A minimal RSS 2.0 syndication feed.";

RssItem item = new RssItem();
item.Title = "Simple RSS Item";
item.Link = new Uri("http://localhost/items/SimpleRSSItem.aspx");
item.Description = "A minimal RSS channel item.";

feed.Channel.AddItem(item);

using(FileStream stream = new FileStream("SimpleRssFeed.xml", FileMode.Create, FileAccess.Write))
{
feed.Save(stream);
}
例子2:
using System.IO;
using Argotic.Common;
using Argotic.Syndication;

RssFeed feed = new RssFeed();

feed.Channel.Link = new Uri("http://localhost");
feed.Channel.Title = "Compact RSS Feed";
feed.Channel.Description = "A minimal and non-indented RSS 2.0 syndication feed.";

RssItem item = new RssItem();
item.Title = "Simple RSS Item";
item.Link = new Uri("http://localhost/items/SimpleRSSItem.aspx");
item.Description = "A minimal RSS channel item.";

feed.Channel.AddItem(item);

using (FileStream stream = new FileStream("CompactRssFeed.xml", FileMode.Create, FileAccess.Write))
{
SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
settings.MinimizeOutputSize = true;

feed.Save(stream, settings);
}

如果在当前页输出可以用如下代码:

      Response.ContentType = "application/rss+xml";
        SyndicationResourceSaveSettings settings = new SyndicationResourceSaveSettings();
        settings.CharacterEncoding = new UTF8Encoding(false);
        feed.Save(Response.OutputStream, settings); 

 

 读取的例子:

 

using Argotic.Extensions.Core;
using Argotic.Syndication;

RssFeed feed = new RssFeed(new Uri("http://example.com/feed.aspx"), "Simple extended syndication feed");
feed.Channel.Description = "An example of how to generate an extended syndication feed.";

// Create and add iTunes information to feed channel
ITunesSyndicationExtension channelExtension = new ITunesSyndicationExtension();
channelExtension.Context.Subtitle = "This feed uses the iTunes syndication extension.";
channelExtension.Context.ExplicitMaterial = ITunesExplicitMaterial.No;
channelExtension.Context.Author = "John Doe";
channelExtension.Context.Summary = "The Argotic syndication framework natively supports the iTunes syndication extension.";
channelExtension.Context.Owner = new ITunesOwner("john.doe@example.com", "John Q. Doe");
channelExtension.Context.Image = new Uri("http://example.com.feed_logo.jpg");

channelExtension.Context.Categories.Add(new ITunesCategory("Extensions"));
channelExtension.Context.Categories.Add(new ITunesCategory("iTunes"));

feed.Channel.AddExtension(channelExtension);

// Create and add iTunes information to channel item
RssItem item = new RssItem();
item.Title = "My Extended Channel Item";
item.Link = new Uri("http://example.com/posts/1234");
item.PublicationDate = DateTime.Now;

RssEnclosure enclosure = new RssEnclosure(47156978L, "audio/mp3", new Uri("http://example.com/myPodcast.mp3"));
item.Enclosures.Add(enclosure);

ITunesSyndicationExtension itemExtension = new ITunesSyndicationExtension();
itemExtension.Context.Author = "Jane Doe";
itemExtension.Context.Subtitle = "This channel item uses the iTunes syndication extension.";
itemExtension.Context.Summary = "The iTunes syndication extension properties that are used vary based on whether extending the channel or an item";
itemExtension.Context.Duration = new TimeSpan(1, 2, 13);
itemExtension.Context.Keywords.Add("Podcast");
itemExtension.Context.Keywords.Add("iTunes");

item.AddExtension(itemExtension);

feed.Channel.AddItem(item);

// Persist extended feed
using (FileStream stream = new FileStream("ExtendedFeed.rss.xml", FileMode.Create, FileAccess.Write))
{
feed.Save(stream);
}
 

 

 

 

posted @ 2010-04-02 09:57 冷火 阅读(76) 评论(0) 编辑
I was looking for good examples of how the ModalPopupExtender control could be used as a confirmation dialog. I was especially curious in seeing implementations where the popup is used to confirm deletes performed on rows of a GridView. I couldn't find any good samples so I figured I would take a shot at it.



Live Demo

If you would like to view a running version of the sample, just follow the Live Demo link. If don't really care about the step by step break down of this implementation you can jump to the bottom of the page to view the full code sample. As always, feedback is encouraged.



Step 1: Add the GridView to your page, placing it inside an UpdatePanel.
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="ToDo List" BackColor="lightblue" Width="95%" />
<asp:GridView
ID="gvToDoList" runat="server" AutoGenerateColumns="false" Width="95%">
<AlternatingRowStyle BackColor="aliceBlue" />
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Item" HeaderText="Description" />
<asp:BoundField DataField="IsCompleted" HeaderText="Complete?" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>

Nothing out of the ordinary here, just a basic GridView contained in an UpdatePanel (don't forget to set UpdateMode to Conditional)


Step 2: Add a TemplateField with a Delete button. Wire up an event handler for the button click.
<asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" OnClick="BtnDelete_Click" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>

You can either explicitly use the OnClick event of the delete button or add the CommandName attribute and implement the RowDeleting event. I chose the former for this sample.

* I also thought about adding the ModalPopupExtender embedded in each of the ItemTemplates and having the OK button just be the delete command for the row. I didn't go down this path because doing so would have included all of the popup markup for each row in the grid. Usual page size's for our gridview is anywhere from 25 to 50 rows. So this didn't seem like a good approach.


Step 3: Add the HTML markup for the modal popup.


<div id="div" runat="server" align="center" class="confirm" style="display:none">
<img align="absmiddle" src="Img/warning.jpg" />Are you sure you want to delete this item?
<asp:Button ID="btnOk" runat="server" Text="Yes" Width="50px" />
<asp:Button ID="btnNo" runat="server" Text="No" Width="50px" />
</div>

Nothing fancy here, just a div with a couple of buttons and a warning image:



* I have explicitly set the style to none on my container elements when using the ModalPopupExtender to avoid the initial flicker that sometimes occurs. Has anyone else seen this?


Step 4: Add the ModalPopupExtender to the page.
<ajaxToolKit:ModalPopupExtender
runat="server" BehaviorID="mdlPopup"
TargetControlID="div" PopupControlID="div"
OkControlID="btnOk" CancelControlID="btnNo" BackgroundCssClass="modalBackground"
/>

Once the ModalPopupExtender has been added to the page, you can go ahead and configure its attributes. The PopupControlID is the id of the div we created in Step 3 that contains the markup we want displayed by the ModalPopup. The OkControlID refers to the ID of the OK button and the CancelControlID refers to the Cancel button (clicking either will dismiss the popup).

In most cases the TargetControlID would point to the button that causes the ModalPopup to be displayed. But for this example, we will always be hiding and showing the popup explicitly from javascript, we can just point this property to our div (this is a required property so we have to set it to something. Some people recommend putting a hidden button or some other element on the page to fake it out, but here I am just setting it to our div).

* I have noticed that the ModalPopup will not be automatically dismissed if it is explicitly displayed using the show method of the animation. Does anyone know if this is a bug or the desired behavior?


Step 5: Add an OnClientClick for the delete button
<asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button
ID="btnDelete" runat="server" OnClientClick="showConfirm(this); return false;"
OnClick="BtnDelete_Click" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>

Next we go back to the markup for our delete button and add the OnClientClick attribute. For the value, we invoke the showConfirm javascript function (created in the next step) passing it a reference to the delete button element. The OnClientClick handler also returns false so the page won't postback after the client script is done running. If this isn't done the delete will happen before the user has a chance to confirm or disallow it!


Step 6: Add the supporting javascript
<script type="text/javascript">
// keeps track of the delete button for the row
// that is going to be removed
var _source;
// keep track of the popup div
var _popup;

function showConfirm(source){
this._source = source;
this._popup = $find('mdlPopup');

// find the confirm ModalPopup and show it
this._popup.show();
}

function okClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// use the cached button as the postback source
__doPostBack(this._source.name, '');
}

function cancelClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// clear the event source
this._source = null;
this._popup = null;
}
</script>
<ajaxToolKit:ModalPopupExtender BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div"
OkControlID="btnOk" OnOkScript="okClick();"
CancelControlID="btnNo" OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />

Now we can implement the final piece. In the previous step, we wired the OnClientClick event of the delete button to the showConfirm javascript function. Now we can implement this function. First we store a reference to the delete button as well as display the modal popup by calling show() on the modal popups animation component (note: in ASP.NET AJAX, DOM elements are retrieved using $get('id') and components are retrieved using $find('id')). The reference to the delete button is stored so we can use it later to initiate the postback (if the user did indeed confirm the delete).

Finally, the ModalPopupExtender contains two properties that allow you to hook into the OK and Cancel buttons and run a little bit of code on the client when the dialog is dismissed. We will hook into both of these events to hide the dialog as well as start the postback causing the item to be deleted if the delete was confirmed.



Step 7: Put it all together.

Here is the complete listing for this page. Again, you can view this page in action here.

Enjoy!


<%@ Page Language="C#" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="head" runat="server">
<title>Delete Confirm Example</title>
<script runat="server">
/// <summary>
///
/// </summary>
public class ToDo
{
private int _id;
private string _item;
private bool _isCompleted;

public ToDo(int id, string item, bool isCompleted)
{
this._id = id;
this._item = item;
this._isCompleted = isCompleted;
}

public int ID
{
get { return this._id; }
}

public string Item
{
get { return this._item; }
}

public bool IsCompleted
{
get { return this._isCompleted; }
}
}

/// <summary>
///
/// </summary>
private System.Collections.Generic.List<ToDo> ToDoList
{
get
{
System.Collections.Generic.List<ToDo> item = this.Session["ToDoList"] as System.Collections.Generic.List<ToDo>;

if (item == null)
{
item = new System.Collections.Generic.List<ToDo>();
item.Add(new ToDo(1, "Go to the store", false));
item.Add(new ToDo(2, "Go to work", true));
item.Add(new ToDo(3, "Feed the dog", false));
item.Add(new ToDo(4, "Take a nap", true));
item.Add(new ToDo(5, "Eat some lunch", false));

this.Session["ToDoList"] = item;
}

return item;
}
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.gvToDoList.DataSource = this.ToDoList;
this.gvToDoList.DataBind();
}
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void BtnDelete_Click(object sender, EventArgs e)
{
// get the gridviewrow from the sender so we can get the datakey we need
Button btnDelete = sender as Button;
GridViewRow row = (GridViewRow)btnDelete.NamingContainer;
// find the item and remove it
ToDo itemToRemove = this.ToDoList[row.RowIndex];
this.ToDoList.Remove(itemToRemove);
// rebind the datasource
this.gvToDoList.DataSource = this.ToDoList;
this.gvToDoList.DataBind();
}

</script>
<script type="text/javascript">
// keeps track of the delete button for the row
// that is going to be removed
var _source;
// keep track of the popup div
var _popup;

function showConfirm(source){
this._source = source;
this._popup = $find('mdlPopup');

// find the confirm ModalPopup and show it
this._popup.show();
}

function okClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// use the cached button as the postback source
__doPostBack(this._source.name, '');
}

function cancelClick(){
// find the confirm ModalPopup and hide it
this._popup.hide();
// clear the event source
this._source = null;
this._popup = null;
}
</script>
<style>
.modalBackground {
background-color:Gray;
filter:alpha(opacity=70);
opacity:0.7;
}
.confirm{
background-color:White;
padding:10px;
width:370px;
}
</style>
</head>
<body>
<form id="form" runat="server" style="font-family:Trebuchet MS;">
<asp:ScriptManager ID="scriptManager" runat="server" />
<div>
<p style="background-color:AliceBlue; width:95%">
Example of using a ModalPopupExtender as a delete confirm button<br />
for the indivdual rows of a GridView. To test out the functionality,<br />
click the Delete button of any of the rows and watch what happens.<br />
</p>
<br />
<asp:UpdatePanel ID="updatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="lblTitle" runat="server" Text="ToDo List" BackColor="lightblue" Width="95%" />
<asp:GridView
ID="gvToDoList" runat="server" AutoGenerateColumns="false" Width="95%">
<AlternatingRowStyle BackColor="aliceBlue" />
<HeaderStyle HorizontalAlign="Left" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Item" HeaderText="Description" />
<asp:BoundField DataField="IsCompleted" HeaderText="Complete?" />
<asp:TemplateField ControlStyle-Width="50px" HeaderStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Button
ID="btnDelete" runat="server" OnClientClick="showConfirm(this); return false;"
OnClick="BtnDelete_Click" Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
<ajaxToolKit:ModalPopupExtender BehaviorID="mdlPopup" runat="server"
TargetControlID="div" PopupControlID="div"
OkControlID="btnOk" OnOkScript="okClick();"
CancelControlID="btnNo" OnCancelScript="cancelClick();" BackgroundCssClass="modalBackground" />
<div id="div" runat="server" align="center" class="confirm" style="display:none">
<img align="absmiddle" src="Img/warning.jpg" />Are you sure you want to delete this item?
<asp:Button ID="btnOk" runat="server" Text="Yes" Width="50px" />
<asp:Button ID="btnNo" runat="server" Text="No" Width="50px" />
</div>
</div>
</form>
</body>
</html>
posted @ 2010-02-09 09:14 冷火 阅读(159) 评论(0) 编辑

//************************************************************//
//下面给出三个简单的方法,后面两个方法是扩展,估计有时用得着
//************************************************************//
  /// <summary>
  /// 缩小图片
  /// </summary>
  /// <param name="strOldPic">源图文件名(包括路径)</param>
  /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
  /// <param name="intWidth">缩小至宽度</param>
  /// <param name="intHeight">缩小至高度</param>
  public void SmallPic(string strOldPic, string strNewPic, int intWidth, int intHeight)
  {

   System.Drawing.Bitmap objPic,objNewPic;
   try
   {
    objPic = new System.Drawing.Bitmap(strOldPic);
    objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
    objNewPic.Save(strNewPic);

   }
   catch(Exception exp){throw exp;}
   finally
   {
    objPic=null;
    objNewPic=null;
   }
  }

  /// <summary>
  /// 按比例缩小图片,自动计算高度
  /// </summary>
  /// <param name="strOldPic">源图文件名(包括路径)</param>
  /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
  /// <param name="intWidth">缩小至宽度</param>
  public void SmallPic(string strOldPic, string strNewPic, int intWidth)
  {

   System.Drawing.Bitmap objPic,objNewPic;
   try
   {
    objPic = new System.Drawing.Bitmap(strOldPic);
    int intHeight=(intWidth / objPic.Width) * objPic.Height;
    objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
    objNewPic.Save(strNewPic);

   }
   catch(Exception exp){throw exp;}
   finally
   {
    objPic=null;
    objNewPic=null;
   }
  }


  /// <summary>
  /// 按比例缩小图片,自动计算宽度
  /// </summary>
  /// <param name="strOldPic">源图文件名(包括路径)</param>
  /// <param name="strNewPic">缩小后保存为文件名(包括路径)</param>
  /// <param name="intHeight">缩小至高度</param>
  public void SmallPic(string strOldPic, string strNewPic, int intHeight)
  {

   System.Drawing.Bitmap objPic,objNewPic;
   try
   {
    objPic = new System.Drawing.Bitmap(strOldPic);
    int intWidth=(intHeight / objPic.Height) * objPic.Width;
    objNewPic=new System.Drawing.Bitmap(objPic,intWidth,intHeight);
    objNewPic.Save(strNewPic);

   }
   catch(Exception exp){throw exp;}
   finally
   {
    objPic=null;
    objNewPic=null;
   }
  }

posted @ 2010-01-06 14:43 冷火 阅读(208) 评论(1) 编辑
通常,为了防止因用户上传有害文件(如木马、黑客程序)引发的安全性问题,Web程序都会对用户允许上传的文件类型加以限制。而本文将要介绍的就是如何在ASP.NET应用程序中利用Web Control的内置属性简单高效地实现限制上传文件类型的功能。

  在调用PostFile对象的SaveAs方法保存上传文件之前,可以通过PostFile对象的FileName属性得到上传的文件名。而有了上传的文件名,就可以采用比对文件后缀名的方法知道上传的文件是否属于允许上传的文件类型。

  根据这个思想,我们就得到了下面这段代码:

                if (Path.GetExtension(FileUpload1.FileName).ToLower() != ".xls")
                {
                    Label1.Text = "本应用程序只允许上传xls格式的excel文件,请重新选择!";
                    return;
                }

   这时如果上传后缀名不是zip的文件,就会发现文件无法上传了。不过,这并表示我们就不能把上传其他格式的文件了。其实,如果在上传前,事先把文件后缀名改成zip,上面这段代码就失去作用了。

之所以会出现这种情况,在于上面的判断仅仅比对了文件名字符串,并没有对文件格式做进一步的分析。因此,如果要彻底限制上传的文件类型,还需要用到PostFile对象的ContentType属性。ContentType属性的功能是获取客户端发送的文件的 MIME (注一)内容类型,由于浏览器在向服务器发送请求前,首先会确定发送内容的MIME类型,并将MIME类型作为信息的一部分提交到服务器端,因此,有了MIME类型信息(注二),就可以准确知道上传文件的实际类型了。

If (FileUpload1.PostedFile.ContentType != "application/zip")

{   

Label1.Text = "本应用程序只允许上传zip格式的文件,请重新选择!"

}

这时,如果再采用修改后缀名的方法上传文件就会发现再也无法上传了。

  注一:MIME是一种技术规范,其中文翻译为多用途Internet邮件扩展(Multipurpose Internet Mail Extensions),主要用来在Internet传输过程中表示不同编码格式的文件;

  注二:要获取不同文件格式的MIME定义,只要启动注册表编辑器,然后在HKEY_CLASSES_ROOT下找到跟后缀名对应的注册表项,如果存在文件格式的MIME定义,在右侧窗口就会显示一个名为“Content Type”的键,而这个键的值就是文件格式的MIME定义。

posted @ 2009-12-04 14:11 冷火 阅读(243) 评论(0) 编辑
摘要: 采集取得页面HTML代码的例子上面已经给出不少了 下面的代码是使用正则表达式取得HTML中内容的代码 Regex regex1 = new Regex(this.NameKey, RegexOptions.Singleline | RegexOptions.IgnoreCase ); MatchCollection collection1 = regex1.Matches(t...阅读全文
posted @ 2009-08-06 09:50 冷火 阅读(165) 评论(0) 编辑
摘要: 比喻输入email地址为 aa@bb.com,bb@dd.com,vvv@cn.com, 最后有逗号也允许? //不允许^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*(,\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*$//允许^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\...阅读全文
posted @ 2009-07-14 16:21 冷火 阅读(406) 评论(0) 编辑
摘要: LumiSoftReceive.aspx.csusing System;using System.Collections.Generic;using System.Data;using System.IO;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Lumi...阅读全文
posted @ 2009-07-06 14:49 冷火 阅读(2615) 评论(22) 编辑
摘要: /Files/xiongeee/dhtmlXTreeprofessionalv1.3.rar阅读全文
posted @ 2009-06-29 10:54 冷火 阅读(63) 评论(0) 编辑
摘要: protected void Button1_Click(object sender, EventArgs e) { Random random=new Random(); int rnumber=random.Next(1, 100); string outPutName = DateTime.Now.ToString("yyyyMMddhhmmss") + rnumber.ToString()...阅读全文
posted @ 2009-06-22 14:48 冷火 阅读(515) 评论(0) 编辑