小编mas*_*son的帖子

如何获取存储在内容文件夹.net中的图像的路径

我正在使用以下代码从Visual Studio的Content / img文件夹中获取图像:

Image image = Image.FromFile(@"~\Content\img\toendra.JPG");
Run Code Online (Sandbox Code Playgroud)

这给了我找不到该文件的错误。但是,如果我给出图像的绝对路径,则可以使用:

Image image = Image.FromFile(@"C:\Users\Stijn\Source\Repos\groep11DotNet\p2groep11.Net\Content\img\toendra.JPG");
Run Code Online (Sandbox Code Playgroud)

我的相对路径有什么问题?

c# asp.net

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

我无法访问我的类属性

我有这个C#类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Handler.FTPClient
{
    public class FTP
    {
        private static string _message = "This is a message";

        public static String message
        {
            get { return _message; }
            set { _message = value; }
        }

        public FTP()
        {
        }

        public static String GetMessage()
        {
            return message;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我试图用这个称呼它:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Handler.FTPClient;

namespace …
Run Code Online (Sandbox Code Playgroud)

c#

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

NewtonSoft Json使用括号方法检索数据

目前,我正在使用YouTube API获取一些数据.数据在json中,我试图获得它的一部分.

我现在面临的问题是我想使用以下方法:

WebClient client = new WebClient();

string jsonData = client.DownloadString("https://www.googleapis.com/youtube/v3/videos?id=" + videoId + "&part=contentDetails&key=");

var results = JsonConvert.DeserializeObject(jsonData);

string duration = results["items"]["contentDetails"]["duration"];
Run Code Online (Sandbox Code Playgroud)

目前,这会导致错误:

无法将带有[]的索引应用于"object"类型的表达式

我现在面临的问题是我不知道如何正确地反序列化对象,所以我可以使用文本索引来获取数据.我之前曾经这样做过,但我无法回忆起它,也无法找到关于我方法的任何信息.

c# json json.net

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

为什么 HangFire 同名重复性工作不起作用?

我安排了具有相同名称和不同参数的作业,但它没有添加到 hangfire 服务器中,只有最后一个作业添加到服务器中,我错过了什么吗?我的代码在下面

        RecurringJob.AddOrUpdate(
            () => Console.WriteLine("HelloNew jobCreated, "),
            Cron.Minutely);
        RecurringJob.AddOrUpdate(
            () => Console.WriteLine("HelloNew jobCreated 12, "),
            Cron.Minutely);
        RecurringJob.AddOrUpdate(
           () => Console.WriteLine("HelloNew jobCreated 2, "),
           Cron.Minutely);
Run Code Online (Sandbox Code Playgroud)

服务器中只添加最后一个作业 Console.WriteLine("HelloNew jobCreated 2, ");

asp.net asp.net-mvc jobs hangfire

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

在asp net core中设置身份验证(asp net 5)

我需要能够像这样在测试中的代码中验证我的用户身份

var identity = new GenericIdentity("ausov@fsb.ru", "UserId");
Thread.CurrentPrincipal = new GenericPrincipal(identity, null);
Run Code Online (Sandbox Code Playgroud)

或者像这样

FormsAuthentication.SetAuthCookie(username, rememberMe);
Run Code Online (Sandbox Code Playgroud)

但这些方法不适用于asp net 5.

asp.net asp.net-mvc asp.net-mvc-5

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

在ASP.net中使用OnCLick的问题

这是我的.aspx文件后面的鳕鱼中的简单重定向功能

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void GoToClicked(object sender, EventArgs e)
{
    Response.Redirect("LoginPage.aspx");
}
}
Run Code Online (Sandbox Code Playgroud)

很基本的.

这是调用它的asp:LinkBut​​ton

<asp:LinkButton ID="LoginLink" runat="server" Text="Login" Font-Bold="true" OnClick="GoToClicked" ></asp:LinkButton>
Run Code Online (Sandbox Code Playgroud)

每当我尝试构建时,我都会收到以下错误:

 Error  1   'GoToClicked' is not a member of 'ASP.default_aspx'.       C:\Users\urMom\Documents\Visual Studio 2013\WebSites\HW_2\Default.aspx   65  
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我试过跟随:

而是使用Server.Transfer

将功能从受保护更改为公共

尝试使用和不使用id标记(包括大写和小写)

c# asp.net webforms

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

C#事件参数有什么作用?

我不明白C#中的事件参数是做什么的.假设我们有一个名为CoffeeButton的按钮,点击它会将您带到另一个名为Coffee的页面,使用名为myFrame的Frame.这是我的代码:

private void CoffeButton_Click(object sender, RoutedEventArgs e)
{
     MyFrame.Navigate(typeof(Coffee));
}
Run Code Online (Sandbox Code Playgroud)

在这种情况下做什么object senderRoutedEventArgs e做什么?

例子很棒!

c# uwp-xaml

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

在浏览器中禁用退格导航

有谁知道如何禁用使用键盘上的“退格”键导航到上一页的功能?

现在,我有一个发票类型的 Web 应用程序,如果用户(在 Mac 上)按退格键删除表单字段中的元素,在到达输入项目的末尾后,如果他们再次按退格键,它会移动到先前浏览的页面,使他们丢失输入的应用程序的数据。

javascript

0
推荐指数
1
解决办法
4509
查看次数

C#将对象添加到List

我刚刚开始学习c#,并且我正在创建一个程序的问题.

我正在创建一个程序,它将创建一个乐透票数,每个票都带有一个ID和六个随机生成的数字.

这是我创建故障单并将其添加到List的代码.

Random random = new Random();// Random number generator
for (int i = 0; i < 1000; i++)
{
    do
    {
    int randomNumber = random.Next(1, 42);// Create randoms numbers between 1 and 42
    ticketNumbers.Add(randomNumber);// Add the random numbers to the ticketNumbers SortedSet                  
    }
    while (ticketNumbers.Count< 6);// Stop Adding once the six numbers is reached

    CTicket firstTicket;
    firstTicket = new CTicket(i, ticketNumbers);// Create ticket object pass i's current value as the ticket id and pass the ticketNumbers sorted set …
Run Code Online (Sandbox Code Playgroud)

c# list sortedset

0
推荐指数
1
解决办法
188
查看次数

在c#中执行SqlCommand.ExecuteNonQuery时如何获取数据库错误?

我有这些陈述:

SqlCommand sqlcmd = new SqlCommand("some query", "some db connection");
sqlcmd.ExecuteNonQuery();
Run Code Online (Sandbox Code Playgroud)

执行此查询时,如何从数据库中获取消息?

例如,如果2行受到影响,我想要SQL Server消息说:

 1 row(s) affected
 1 row(s) affected
Run Code Online (Sandbox Code Playgroud)

在C#代码中.或者,例如,如果与主键发生冲突,我的意思是我试图插入存在主键的行,我希望收到数据库错误消息,其中显示:"主键重复".

c# sql sql-server sqlcommand

0
推荐指数
1
解决办法
1251
查看次数