小编Joh*_*ann的帖子

将文件作为附件发送后锁定文件

我发送文件作为附件:

            // Create  the file attachment for this e-mail message.
            Attachment data = new Attachment(filePath, MediaTypeNames.Application.Octet);
            // Add time stamp information for the file.
            ContentDisposition disposition = data.ContentDisposition;
            disposition.CreationDate = System.IO.File.GetCreationTime(filePath);
            disposition.ModificationDate = System.IO.File.GetLastWriteTime(filePath);
            disposition.ReadDate = System.IO.File.GetLastAccessTime(filePath);
            // Add the file attachment to this e-mail message.
            message.Attachments.Add(data);
Run Code Online (Sandbox Code Playgroud)

然后我想将文件移动到另一个文件夹,但是当我尝试这样做时

                    try
                    {
                        //File.Open(oldFullPath, FileMode.Open, FileAccess.ReadWrite,FileShare.ReadWrite);
                        File.Move(oldFullPath, newFullPath);

                    }
                    catch (Exception ex)
                    {
                    }
Run Code Online (Sandbox Code Playgroud)

它抛出了一个异常,即该文件已在另一个进程中使用.如何解锁此文件以便将其移动到此位置?

c# attachment locked-files

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

TS2531:对象可能是'null'

我有以下功能: -

uploadPhoto() {
    var nativeElement: HTMLInputElement = this.fileInput.nativeElement;

    this.photoService.upload(this.vehicleId, nativeElement.files[0])
        .subscribe(x => console.log(x));
}
Run Code Online (Sandbox Code Playgroud)

但是在nativeElement.files [0]上,我收到了一个打字稿错误,"对象可能是'null'".有人可以帮我解决这个问题吗?

我试图将nativeElement声明为null值,但是没有成功.

谢谢你的帮助和时间.

typescript angular

12
推荐指数
4
解决办法
9830
查看次数

在Razor/MVC3中显示来自db的图像

我在db中有一个表,它有以下内容: - CountryID,CountryName和CountryImage.

现在我试图在索引中显示图像,我在视图中有以下内容: -

        <td>
        @if (item.Image != null)
        {
            <img src="@Model.GetImage(item.Image)" alt="@item.CountryName"/>    
        }
Run Code Online (Sandbox Code Playgroud)

然后在ViewModel我有: -

        public FileContentResult GetImage(byte[] image)
    {
        if (image != null)
            return new FileContentResult(image, "image/jpeg");
        else
        {
            return null;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是我无法正确看到图像.

我究竟做错了什么?

在此先感谢您的帮助和时间

UPDATE

好的,我在视图中实现了以下内容: -

        <td>
        @if (item.Image != null)
        {
            <img src="@Url.Action("GetImage", "CountryController", new { id = item.CountryID })" alt="@item.CountryName" />             
        }
    </td>
Run Code Online (Sandbox Code Playgroud)

并在CountryController中: -

        public ActionResult GetImage(int id)
    {
        var firstOrDefault = db.Countries.Where(c => c.CountryID == id).FirstOrDefault();
        if (firstOrDefault != null) …
Run Code Online (Sandbox Code Playgroud)

razor c#-4.0 asp.net-mvc-3

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

单元测试Web Api控制器

我对单元测试相当新,我正在尝试为我创建的Web Api控制器创建一个单元测试,它返回一个品牌列表.

我的WebApi控制器Get()方法如下所示: -

[HttpGet("/api/Brands/Get", Name = "GetBrands")]
public async Task<IActionResult> Get()
{
    var brands = await _brandsService.GetAll(null, "Image");
    return Json(brands);
}
Run Code Online (Sandbox Code Playgroud)

通用服务方法如下所示: -

public async Task<List<T>> GetAll(
    Func<IQueryable<T>, 
    IOrderedQueryable<T>> orderBy = null, 
    string includeProperties = null)
{
    return await _genericRepository.GetAll(orderBy, includeProperties);
}
Run Code Online (Sandbox Code Playgroud)

而Generic Repo方法如下所示: -

public async Task<T> Get<TKey>(Expression<Func<T, bool>> filter = null, string includeProperties = "", bool noTracking = false)

{
    includeProperties = includeProperties.Trim() ?? string.Empty;
    IQueryable<T> query = Context.Set<T>();

    if (noTracking)
    {
        query.AsNoTracking();
    }

    if …
Run Code Online (Sandbox Code Playgroud)

c# nunit unit-testing moq asp.net-web-api

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

在 node-sass@4.11.0 安装后脚本失败。无法运行这个

我已经解决了有关此问题的所有问题,但似乎找不到任何可行的方法。

我收到此错误:-

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.11.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the node-sass@4.11.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Run Code Online (Sandbox Code Playgroud)

我试图再次删除 node_modules 和 npm install。我还尝试删除 node_modules 中的 node-sass 文件夹,但 npm install -g node-sass@latest 也不起作用。我也试过

npm install -g node --unsafe-perm=true --allow-root
Run Code Online (Sandbox Code Playgroud)

npm uninstall node-sass
npm cache clean --force
npm install -g node-sass@latest …
Run Code Online (Sandbox Code Playgroud)

npm node-modules reactjs node-sass

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

Visual Studio 代码中的集成终端在外部而非内部打开

我已经重新安装了 Visual Studio Code,出于某种原因,当我执行Ctrl+ Shift+`快捷方式时,不是在 VS Code 中打开终端窗口,而是打开了一个外部命令窗口,这很烦人。

任何人都知道在内部取回它是什么设置?

我尝试了文件->首选项->设置->终端,然后设置了第一个选项“自定义要启动的终端类型”。来集成。

我需要设置任何其他设置吗?

terminal visual-studio-code vscode-settings

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

检查2 IEnumerables之间的差异

所以基本上我有以下2 IEnumerable lists

List A = {"Personal", "Tech", "Social"}
List B = {"Personal", "Tech", "General"}
Run Code Online (Sandbox Code Playgroud)

现在,我要实现的是,得到的区别List AList B,在这种情况下,社会通用.

我还需要确定Social是额外的,List AGeneralList B相应的插入和删除.

我还可以有另一个场景

 List A = {"Personal", "Tech"}
 List B = {"Personal", "Tech", "General"}
Run Code Online (Sandbox Code Playgroud)

在这种情况下,它将返回通用 "

我怎么能这样做LINQ

c# linq ienumerable list

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

实体框架使用单个插入添加多个相关实体

我有一个像这样的 GenericService Add 方法:-

    public bool Add(T entity, Expression<Func<T, bool>> filter = null)
    {
        try
        {
            _genericRepository.Add(entity, filter);
        }
        catch (Exception e)
        {
            return false;
        }
        return true;
    }
Run Code Online (Sandbox Code Playgroud)

和一个 GenericRepository Add 方法,如下所示:-

    public void Add(T entity, Expression<Func<T, bool>> filter = null)
    {
        var existing = Get<T>(filter);
        if (existing.Result != null) return;
        Context.Add(entity);
        Save();
    }
Run Code Online (Sandbox Code Playgroud)

这是我在 ProductsController 中所做的调用:-

    [HttpPost]
    public IActionResult Create([FromBody] Product product)
    {
        if (product == null)
            return BadRequest();

        var result = _productsService.Add(product, m => m.Name == product.Name); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc entity-framework asp.net-core-mvc

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

将大型xml上载到WCF REST服务 - > 400 Bad request

我一直在努力寻找这个错误但到目前为止没有运气.

所以我通过这个web.config在我的客户端上有一个服务

  <system.serviceModel>
<serviceHostingEnvironment>
  <baseAddressPrefixFilters>
    <add prefix="http://www.mywebsite.com/"/>
  </baseAddressPrefixFilters>
</serviceHostingEnvironment>
<services>
  <service behaviorConfiguration="ServiceBehavior" name="UploadService">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration=""
      contract="IUploadService">
      <identity>
        <dns value="http://www.mywebsites.com/" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehavior" maxReceivedMessageSize="4194304">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>
Run Code Online (Sandbox Code Playgroud)

在客户端我有这个配置

  <system.serviceModel>
<bindings>
  <wsHttpBinding>
    <binding name="WSHttpBinding_IUploadService" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="524288" maxReceivedMessageSize="4194304"
      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
      allowCookies="false">
      <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
        maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
      <reliableSession ordered="true" inactivityTimeout="00:30:00"
        enabled="false" />
      <security mode="Message">
        <transport clientCredentialType="Windows" …
Run Code Online (Sandbox Code Playgroud)

rest wpf wcf

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

部分视图不令人耳目一新

我在cshtml页面上有一个部分视图如下: -

@model MvcCommons.ViewModels.CompositeViewModel

@{
ViewBag.Title = "Edit";
}

@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
    <fieldset>
    <legend>Article</legend>

    @Html.HiddenFor(model => model.ArticleViewModel.Article.ArticleID)

    <div class="editor-label">
        @Html.LabelFor(model => model.ArticleViewModel.Article.CategoryID, "Category")
    </div>
    <div class="editor-field">
        @Html.DropDownListFor(model => model.ArticleViewModel.Article.CategoryID, (SelectList)ViewBag.CategoryID) 
        @Html.ValidationMessageFor(model => model.ArticleViewModel.Article.CategoryID)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ArticleViewModel.Article.ArticleTitle)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ArticleViewModel.Article.ArticleTitle)
        @Html.ValidationMessageFor(model => model.ArticleViewModel.Article.ArticleTitle)
    </div>

    <div class="editor-label">
        @Html.LabelFor(model => model.ArticleViewModel.Article.ArticleDate)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ArticleViewModel.Article.ArticleDate)
        @Html.ValidationMessageFor(model => model.ArticleViewModel.Article.ArticleDate)
    </div>

        @Html.HiddenFor(model => model.PageViewModel.Page.PageTitle, new { id = "PageTitle" })
        @Html.HiddenFor(model => model.PageViewModel.Page.PageAction, new { id …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc jquery partial-views razor

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