小编mse*_*dio的帖子

在十进制上舍入扩展时出错 - 无法使用实例引用访问; 用类型名称来限定它

我已经多次使用扩展方法,并没有遇到这个问题.任何人都有任何想法,为什么这会引发错误?

 /// <summary>
 /// Rounds the specified value.
 /// </summary>
 /// <param name="value">The value.</param>
 /// <param name="decimals">The decimals.</param>
 /// <returns></returns>
 public static decimal Round (this decimal value, int decimals)
 {
     return Math.Round(value, decimals);
 }
Run Code Online (Sandbox Code Playgroud)

用法:

decimal newAmount = decimal.Parse("3.33333333333434343434");
this.rtbAmount.Text = newAmount.Round(3).ToString();
Run Code Online (Sandbox Code Playgroud)

newAmount.Round(3)抛出了编译器错误:

Error   1   Member 'decimal.Round(decimal)' cannot be accessed with an instance     reference; qualify it with a type name instead
Run Code Online (Sandbox Code Playgroud)

.net c# extension-methods rounding visual-studio-2010

8
推荐指数
1
解决办法
1288
查看次数

SSRS使Tablix适合导出的pdf页面

我目前在SSRS报告中有一个Matrix.通常,矩阵将以纵向模式固定到标准页面,但是有时列的长度将超过页面.有没有办法让SSRS将报表呈现为PDF,此Matrix将自动调整大小并缩小其所有内容,即:字体,列宽以适合页面?我不想收缩SSRS报告中的所有对象来修复页面,只是缩小Matrix的宽度.

reporting-services ssrs-2008 ssrs-tablix

8
推荐指数
1
解决办法
8466
查看次数

System.Net.Mail和MailMessage不立即发送消息

当我使用System.Net.Mail发送邮件时,似乎邮件不会立即发送.他们在到达我的收件箱之前需要一两分钟.一旦我退出应用程序,所有消息都会在几秒钟内收到.是否有某种邮件消息缓冲区设置可以强制SmtpClient立即发送消息?

public static void SendMessage(string smtpServer, string mailFrom, string mailFromDisplayName, string[] mailTo, string[] mailCc, string subject, string body)
{
    try
    {
        string to = mailTo != null ? string.Join(",", mailTo) : null;
        string cc = mailCc != null ? string.Join(",", mailCc) : null;

        MailMessage mail = new MailMessage();
        SmtpClient client = new SmtpClient(smtpServer);

        mail.From = new MailAddress(mailFrom, mailFromDisplayName);
        mail.To.Add(to);

        if (cc != null)
        {
            mail.CC.Add(cc);
        }

        mail.Subject = subject;
        mail.Body = body.Replace(Environment.NewLine, "<BR>");
        mail.IsBodyHtml = true;

        client.Send(mail);
    }
    catch (Exception …
Run Code Online (Sandbox Code Playgroud)

c# smtp system.net.mail smtpclient mailmessage

6
推荐指数
1
解决办法
7958
查看次数

应用程序处于后台状态时的CLLocationManager

我的问题是:CLLocationManager是否继续运行,而我的应用程序处于非活动状态?

iphone objective-c ipad ios

6
推荐指数
2
解决办法
7526
查看次数

检查ControlControl中的Control是否为Textbox

要清除我的文本框,我在表单中使用以下代码:

foreach (Control c in this.Controls)
{
    if (c is TextBox || c is RichTextBox)
    {
        c.Text = "";
    }
}
Run Code Online (Sandbox Code Playgroud)

但现在我的文本框位于TabControl中.如何对文本框运行相同类型的检查,如果控件是文本框,则将值设置为"".我已经尝试过使用:

foreach(Control c in tabControl1.Controls)
Run Code Online (Sandbox Code Playgroud)

但这没效果.

c# controls tabcontrol winforms

6
推荐指数
2
解决办法
2万
查看次数

使用Windows身份验证和匿名身份验证获取UserPrincipal

以下代码仅适用于IIS中仅为我们网络上的本地用户启用Windows身份验证的情况.

using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain))
{
     UserPrincipal up = UserPrincipal.FindByIdentity(ctx, userName);
     return up;
}
Run Code Online (Sandbox Code Playgroud)

否则会抛出此异常:

[ArgumentException :(&(objectCategory = user)(objectClass = user)(|(userPrincipalName =)(distinguishedName =)(name =)))搜索过滤器无效.] System.DirectoryServices.ResultsEnumerator.MoveNext()+434305 System .DirectoryServices.SearchResultCollection.get_InnerList()+282 System.DirectoryServices.SearchResultCollection.get_Count()+ 9 System.DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRefHelper(Type principalType,String urnScheme,String urnValue,DateTime referenceDate,Boolean useSidHistory)+1898 System. DirectoryServices.AccountManagement.ADStoreCtx.FindPrincipalByIdentRef(类型principalType,String urnScheme,String urnValue,DateTime referenceDate)+85 System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context,Type principalType,Nullable`1 identityType,String identityValue,DateTime refDate)+ 211 System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context,String identi)tyValue)+95 WebApplication1.Index.GetUserPrincipal(String userName)在C:\ Users\xxx\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Index.aspx.cs:38 WebApplication1.Index.Page_Load(Object sender,EventArgs) e)在C:\ Users\xxx\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Index.aspx.cs:19 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,Object o,Object t,EventArgs e) )+25 System.Web.UI.Control.LoadRecursive()+71 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+3064

是否有任何方法可以让这个用于获取本地用户UserPrincipal 而Windows和匿名身份验证都打开?

.net c# asp.net iis-7.5 userprincipal

6
推荐指数
1
解决办法
6447
查看次数

INotifyPropertyChanged用于数据绑定之外

我从未使用过INotifyPropertyChanged,我正在考虑在新的应用程序中广泛使用它.

我的问题是,使用INotifyPropertyChanged接口以便为数据绑定控件以外的其他内容提供事件通知是否"合适"?

从在线的一些示例中可以看出,该接口广泛用于通知网格,例如数据更改时.我有各种各样的场景,我需要其他类通知其他类中的数据更改,我想知道你是否认为实现这个接口更清晰,并在setter上执行更改的调用,或者更确切地说是创建常规事件.

c# .net-4.0 visual-studio-2010 inotifypropertychanged

5
推荐指数
1
解决办法
779
查看次数

Outlook加载项和禁用/隐藏自定义菜单项

我已经创建了一个Outlook加载项,我正在使用XML功能区配置文件来指定一个新选项卡和按钮.该按钮加载到outlook中的新选项卡中.现在有时,基于用户我们希望能够隐藏或禁用这些按钮.通过Outlook Interop api禁用自定义选项卡上的菜单按钮的最简单方法是什么?

我的第一个猜测是,我需要在创建功能区后迭代一些命令栏集合,然后搜索我的菜单按钮,但我不确定这些集合在哪里.

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    this.ribbon = new MyRibbon();

    // loop through tabs and ribbon items, look for my custom control, and enabled/disable specific buttons.

    return this.ribbon;
}
Run Code Online (Sandbox Code Playgroud)

c# outlook ribbon office-interop outlook-addin

5
推荐指数
1
解决办法
4264
查看次数

Silverlight:WCF在服务器上出错,但本地主机正常

我有silverlight应用程序,并且出现此错误:

[Async_ExceptionOccurred]
Arguments: 
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.61118.00&File=System.dll&Key=Async_ExceptionOccurred INNER >System.ServiceModel.CommunicationException: [CrossDomainError]
Arguments: http://localhost/pthaba/SimpleWCF.svc
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.61118.00&File=System.ServiceModel.dll&Key=CrossDomainError ---> System.Security.SecurityException ---> System.Security.SecurityException: [Arg_SecurityException]
Arguments: 
Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=5.0.61118.00&File=mscorlib.dll&Key=Arg_SecurityException
Run Code Online (Sandbox Code Playgroud)

我有WCF服务,并且可以在浏览器上正常工作。我在根站点(位于WCF服务所在的位置)中具有如下所示的clientacesspolicy.xml。

<?xml version="1.0" encoding="utf-8" ?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from …
Run Code Online (Sandbox Code Playgroud)

silverlight wcf iis-7 silverlight-4.0

5
推荐指数
1
解决办法
7275
查看次数

Winforms ReportViewer 并在导出后打开

在 ReportViewer 中使用默认导出按钮时,是否可以简单地提示用户打开导出的报告?我查看了 ReportExport 事件,尽管这会在导出发生之前触发。我唯一能想到的就是取消 ReportExport 并创建我自己的导出功能,尽管我希望我不需要这样做。导出发生后是否有任何我错过的事件?

visual-studio-2010 winforms c#-4.0 report-viewer2010

3
推荐指数
1
解决办法
7776
查看次数