use会捕获异常还是抛出异常?即
using (StreamReader rdr = File.OpenText("file.txt"))
{
//do stuff
}
Run Code Online (Sandbox Code Playgroud)
如果streamreader抛出异常是通过使用或抛出来捕获的,那么调用函数可以处理它吗?
似乎.NET无法使用GDI库打开JP2(Jpeg 2000)文件.我在谷歌搜索但找不到任何库或示例代码来执行此操作.
有人有任何想法吗?除非我必须,否则我真的不想为图书馆付费.
<Document>
<A>
<B>
<C></C>
</B>
</A>
<E>
<F>
<C></C>
</F>
<G>
<C></C>
</G>
</E>
</Document>
Run Code Online (Sandbox Code Playgroud)
如果我将上述XML加载到XmlDocument并使用XPath查询在C上执行SelectSingleNode // C
XmlNode oNode = oDocument.SelectSingleNode("E");
XmlNodeList oNodeList = oNode.SelectNodes("//C");
为什么它会从Under B返回节点,而我预期会发生它只会从E下返回节点
合理?
编辑:我怎么才能让它从那个节点开始返回?
我有一个链接按钮,用于从页面内容构建mailto.什么是从javascript启动它而不打开空白窗口或干扰它被调用的窗口的最佳方法?
function Email()
{
var sMailTo = "mailto:";
var sBody = "";
var alSelectedCheckboxes = new Array();
$("input:checkbox[CheckBoxType=Email]:checked").each(function()
{
alSelectedCheckboxes.push($(this).val());
});
if (alSelectedCheckboxes.length > 0)
{
for (var i=0; i<alSelectedCheckboxes.length; i++)
{
sBody += alSelectedCheckboxes[i];
sBody += "\n";
}
sMailTo += escape("<Insert Recipients Here>") +"?subject=" +escape("<Insert Subject Here>") +"&body=" +escape(sBody);
window.location.href = sMailTo;
}
else
{
alert("Please select some results");
}
}
Run Code Online (Sandbox Code Playgroud)
简单的功能在上面.window.location.href无法正常工作,除非它是Firefox/Chrome(它在IE8中重绘页面).我也尝试过window.open(sMailTo,"_ self")但是在IE8中再次打破了它所调用的页面.
我确定这是一个愚蠢的问题...... :-)
谢谢
假设您有几个webpart,一个作为控制器,另外几个从控制器获取信息并对其进行操作.使用ASP 2.0中引入的Consumer/Producer接口进行建模非常容易.
你怎么能在保持上述情况的同时增加互动?
一个简单的例子是:用户将信息输入到执行搜索的webpart A中,结果将显示在webpart B上.Webpart C允许您过滤应该触发webpart A重新提交查询的结果,从而更新结果是B.
在WSS 3.0中似乎不可能这样做,因为在任何时候只允许在所有连接中使用1个接口.
这甚至有意义吗?:-)
在用户控件中,我在UpdatePanel内部有一个Repeater(在ModalPopupExtender中显示了id.使用MyDTO对象的数组列表对Repeater进行数据绑定.列表中的每个Item都有两个按钮.设置了ImageURL和CommandArgument.
这段代码第一次正常工作但此后CommandArgument是错误的.看起来显示器正确更新但DTO不是,并且发送的CommandArgument是刚刚删除的.
任何人都可以发现代码的任何问题吗?
编辑:我刚刚在代码中添加了一个CollapsiblePanelExtender.当我现在删除一个项目并展开面板时,之前已删除(并从显示中删除)的项目已经返回.似乎在发动机罩下没有正确重建中继器.
ASCX
<asp:UpdatePanel ID="ViewDataDetail" runat="server" ChildrenAsTriggers="true">
<Triggers>
<asp:PostBackTrigger ControlID="ViewDataCloseButton" />
<asp:AsyncPostBackTrigger ControlID="DataRepeater" />
</Triggers>
<ContentTemplate>
<table width="100%" id="DataResults">
<asp:Repeater ID="DataRepeater" runat="server" OnItemCommand="DataRepeater_ItemCommand" OnItemDataBound="DataRepeater_ItemDataBound">
<HeaderTemplate>
<tr>
<th><b>Name</b></th>
<th><b> </b></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<b><%#((MyDTO)Container.DataItem).Name%></b>
</td>
<td>
<asp:ImageButton CausesValidation="false" ID="DeleteData" CommandName="Delete" runat="server" />
<asp:ImageButton CausesValidation="false" ID="RunData" CommandName="Run" runat="server" />
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>Description : </td>
<td><%#((MyDTO)Container.DataItem).Description%></td>
</tr>
<tr>
<td>Search Text : </td>
<td><%#((MyDTO)Container.DataItem).Text%></td>
</tr>
</table>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>
Run Code Online (Sandbox Code Playgroud)
代码隐藏
public DeleteData …Run Code Online (Sandbox Code Playgroud) 我有一个Sharepoint WebPart,可以加载自定义用户控件.用户控件包含一个Repeater,而Repeater又包含多个LinkButtons.
在Webpart中的RenderContent调用中,我有一些代码来添加事件处理程序:
ArrayList nextPages = new ArrayList();
//populate nextPages ....
AfterPageRepeater.DataSource = nextPages;
AfterPageRepeater.DataBind();
foreach (Control oRepeaterControl in AfterPageRepeater.Controls)
{
if (oRepeaterControl is RepeaterItem)
{
if (oRepeaterControl.HasControls())
{
foreach (Control oControl in oRepeaterControl.Controls)
{
if (oControl is LinkButton)
{
((LinkButton)oControl).Click += new EventHandler(PageNavigateButton_Click);
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是从不调用函数PageNavigateButton_Click.我可以看到它被添加为调试器中的事件处理程序.
有任何想法吗?我很难过如何做到这一点.
我有一个用C#编写的自定义HTTP服务器,它给我原始的HTTP请求...
GET /ACTION=TEST HTTP/1.1 Host: localhost:8080 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-gb,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive
我可以使用.NET框架中的某些东西来解析它,还是我必须手动完成?
干杯
我们有一个页面将数据发布到ISO-8859-1中的ASP.NET应用程序
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<title>`Sample Search Invoker`</title>
</head>
<body>
<form name="advancedform" method="post" action="SearchResults.aspx">
<input class="field" name="SearchTextBox" type="text" />
<input class="button" name="search" type="submit" value="Search >" />
</form>
Run Code Online (Sandbox Code Playgroud)
并在后面的代码(SearchResults.aspx.cs)
System.Collections.Specialized.NameValueCollection postedValues = Request.Form;
String nextKey;
for (int i = 0; i < postedValues.AllKeys.Length; i++)
{
nextKey = postedValues.AllKeys[i];
if (nextKey.Substring(0, 2) != "__")
{
// Get basic search text
if (nextKey.EndsWith(XAEConstants.CONTROL_SearchTextBox))
{
// Get search text value
String sSentSearchText = postedValues[i];
System.Text.Encoding iso88591 = System.Text.Encoding.GetEncoding("iso-8859-1");
System.Text.Encoding utf8 = System.Text.Encoding.UTF8;
byte[] …Run Code Online (Sandbox Code Playgroud) 我们在ASP.NET 2.0应用程序中使用日志记录应用程序块,该应用程序块通过以下方式调用:
public class BaseLogEntry : LogEntry
{
public void CloseLog()
{
try
{
Logger.Writer.Dispose();
}
catch (Exception)
{ }
}
}
public class GeneralLogEntry : BaseLogEntry
{
/// <summary>
///
/// </summary>
/// <param name="message"></param>
public GeneralLogEntry(string message) : this(message, 2) { }
/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="priority"></param>
public GeneralLogEntry(string message, int priority): base()
{
Categories.Add("General");
Priority = priority;
Severity = System.Diagnostics.TraceEventType.Information;
Message = message;
CloseLog();
}
}
Run Code Online (Sandbox Code Playgroud)
当我们将IIS中的工作进程数增加到1以上时,日志文件会添加一个唯一的GUID,如下所示:
068aa49c-2bf6-4278-8f91-c6b65fd1ea3aApplication.log
应用程序生成的几个日志文件都是"Rolling Flat File …
iis enterprise-library asp.net-2.0 logging-application-block
我有一个复杂的ASP.NET项目(ASP.NET 2.0),我正在尝试重构代码.
每个页面都扩展了一个名为GenericPage的基页,它有一组在页面生命周期中使用的函数(访问session/HttpApplicationState对象的函数).还有相当多的用户控件执行类似的操作,但扩展了一个单独的基类.
我们开始重新实现许多代码以使用WebServices,并且他们需要访问相同的功能.WebServices将扩展GenericWebService.
鉴于一个扩展了Page而另一个扩展了WebService,两者都不能从同一个类扩展,那么构建这个的最佳方法是什么?我不想在3个单独的基类中复制代码,因为它越来越难以维护.
我可以把这些非静态功能放在一个共同的地方吗?
谢谢
我们使用SVN进行源代码版本控制,我们是一个由三个开发人员组成的小团队,使用AGILE方法.
最初我们的代码被放入主干,各种版本已经从它分支出来.每个版本都是客户端特定的,但随着代码的改进,我们经常跳过合并回主干并从当前版本合并到另一个客户特定版本,很少合并回主干.主干现在完全过时了,我们想要通过多年来在所有这些分支机构中进行的累积代码更改来创建一个新的全新主干.
问题是这样,如果我们删除其中一个版本(具体来说,将它们从SVN归档然后删除)会发生什么,链是否会分崩离析或者SVN是否是硬链接的.我的假设是,在没有指向物理数据的引用之前,实际上不会删除数据.我不清楚SVN是如何工作的,是数据的实际位置是无关紧要的.
有没有办法将所有修订历史记录导出到可以驻留在主干中的实际副本,或者这是荒谬且毫无意义的.
c# ×6
asp.net ×3
.net ×2
asp.net-2.0 ×2
sharepoint ×2
web-parts ×2
.net-2.0 ×1
asp.net-ajax ×1
branch ×1
encoding ×1
exception ×1
gdi ×1
http ×1
iis ×1
iso-8859-1 ×1
javascript ×1
jpeg2000 ×1
jquery ×1
mailto ×1
refactoring ×1
repeater ×1
svn ×1
updatepanel ×1
using ×1
utf-8 ×1
xml ×1
xpath ×1