Directory.GetFiles方法在第一次遇到没有访问权限的文件夹时失败.
该方法抛出一个UnauthorizedAccessException(可以捕获),但到此时,该方法已经失败/终止.
我正在使用的代码如下:
try
{
// looks in stated directory and returns the path of all files found
getFiles = Directory.GetFiles(
@directoryToSearch,
filetype,
SearchOption.AllDirectories);
}
catch (UnauthorizedAccessException)
{
}
Run Code Online (Sandbox Code Playgroud)
据我所知,没有办法事先检查某个文件夹是否具有定义的访问权限.
在我的示例中,我正在通过网络搜索磁盘,当我遇到仅限root访问权限的文件夹时,我的程序失败了.
我使用以下代码片段成功删除了文件的只读属性:
在main.cs中
FileSystemInfo[] sqlParentFileSystemInfo = dirInfo.GetFileSystemInfos();
foreach (var childFolderOrFile in sqlParentFileSystemInfo)
{
RemoveReadOnlyFlag(childFolderOrFile);
}
private static void RemoveReadOnlyFlag(FileSystemInfo fileSystemInfo)
{
fileSystemInfo.Attributes = FileAttributes.Normal;
var di = fileSystemInfo as DirectoryInfo;
if (di != null)
{
foreach (var dirInfo in di.GetFileSystemInfos())
RemoveReadOnlyFlag(dirInfo);
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不适用于文件夹.运行代码后,当我转到该文件夹时,右键单击并执行属性,这是我看到的:

虽然只读标志从它下面的文件中删除了,但仍然会检查它.这会导致进程无法删除此文件夹.当我手动删除标志并重新运行进程(bat文件)时,它可以删除该文件(所以我知道这不是bat文件的问题)
如何在C#中删除此标志?
我刚刚发现自己面临一个新的挑战:使用像纯文本处理更像Web的字处理器.为此设计一个很好的框架是我无法等待的开始,但我确实需要知道GUI端的可能性(它可能会有很多GUI挑战).
所以基本的东西,我需要某种控制,我可以使我的文本的部分可点击/鼠标覆盖.
我是WPF的新手,不知道如何做到这一点.有谁知道如何制作这个?有例子吗?对此有控制吗?
提前致谢
编辑:
我发现了一些使用richtextbox的方法:
// Create a FlowDocument to contain content for the RichTextBox.
FlowDocument myFlowDoc = new FlowDocument();
// Add paragraphs to the FlowDocument.
Hyperlink myLink = new Hyperlink();
myLink.Inlines.Add("hyperlink");
myLink.NavigateUri = new Uri("http://www.stackoverflow.com");
// Create a paragraph and add the Run and hyperlink to it.
Paragraph myParagraph = new Paragraph();
myParagraph.Inlines.Add("check this link out: ");
myParagraph.Inlines.Add(myLink);
myFlowDoc.Blocks.Add(myParagraph);
// Add initial content to the RichTextBox.
richTextBox1.Document = myFlowDoc;
Run Code Online (Sandbox Code Playgroud)
我现在在我的文本框中得到一个很好的超链接...除非我点击它,没有任何反应.我在这里失踪了什么?
Bootstrap允许使用表单内部输入的验证状态
class="form-group has-error".但这不起作用<textarea>,奇怪的是,它没有help-inline任何帮助吗?
编辑:这是完整的输入组:
<div class="form-group">
<label for="desc" class="col-sm-2 control-label">Description:*</label>
<div class="col-sm-10">
<textarea autocomplete="off" class="form-control" rows="5" name="desc" id="desc"></textarea>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我正在使用 Daniel Schroeder 的“每次构建后从项目创建新的 NuGet 包”NuGet 包,通过 Visual Studio 2013 自动从我的项目创建 NuGet 包。在 .nuspec 文件中指定组依赖项时,我遇到了问题。这是我的 .nuspec 文件中的内容:
<dependencies>
<group targetFramework=".NETFramework3.5">
<dependency id="BitMiracle.LibTiff.NET" version="2.4.500.0" />
</group>
<group targetFramework=".NETFramework3.5">
<dependency id="FAImage.Net35" version="1.0.0" />
</group>
<group targetFramework="Silverlight5.0">
<dependency id="FAImage.SL50" version="1.0.0" />
</group>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
依赖项包含在包中,但它们不依赖于 .nuspec 文件标记中指定的特定平台。它们都被列为“非特定于框架”。通过 NuGet Package Explorer 创建相同的包时,可以正确获取依赖项。任何帮助将不胜感激。
假设我有这个功能我想测试:
var test = function () {
console.log('words!');
};
Run Code Online (Sandbox Code Playgroud)
我会写这样的东西
define('test()', function () {
it('prints "words!" to the screen', function() {
test();
expect(<browser logs>).toContain('words!'); // TODO
}
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何查看控制台日志,或者这是否可能。最好,我会在任何浏览器中执行此操作,或者至少是 PhantomJS。
我正在将参数从一个组件传输到 app.component.ts 但错误即将到来。错误:没有 NavParams 的提供者。
这是我的app.component.ts:
import { FrontPage } from "./../pages/front/front";
import { Component, ViewChild } from "@angular/core";
import { Nav, Platform, NavController, NavParams } from "ionic-angular";
import { StatusBar } from "@ionic-native/status-bar";
import { SplashScreen } from "@ionic-native/splash-screen";
import { HomePage } from "../pages/home/home";
import { ListPage } from "../pages/list/list";
import { ProductPage } from "../pages/product/product";
import { LoginpagePage } from "../pages/loginpage/loginpage";
@Component({
templateUrl: "app.html",
})
export class MyApp {
@ViewChild(Nav) nav: Nav;
menuclick: boolean = …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的 JS函数,我想测试它,但是当我运行它时,它显示错误预期的间谍日志被称为我做错了什么?
功能
function helloWorld() {
console.log('hey');
}
Run Code Online (Sandbox Code Playgroud)
测试规格
describe('Hello world', function () {
it('says hello', function () {
spyOn(console,'log').and.callThrough();
expect(console.log).toHaveBeenCalled();
});
});
Run Code Online (Sandbox Code Playgroud) 我试图按照这个指令来完成它,但我刚刚开始使用WPF.
如何使用可以在不同TabControl中重用的UserControl来执行此操作?TabControl样式中的哪一个是"Header"ContentPresenter ?
以下是https://github.com/MahApps/MahApps.Metro/issues/281上的说明
另一种方法是修改/创建一个样式 - 然后问题就是以通用的方式将它连接到一个实际的'close'事件.
如果查看TabControl样式,您将看到"Header"ContentPresenter.如果你将它包装在一个堆栈面板中并添加一个如下按钮:
Run Code Online (Sandbox Code Playgroud)<StackPanel Orientation="Horizontal"> <Label x:Name="root" FontSize="26.67"> <ContentPresenter ContentSource="Header" RecognizesAccessKey="True" /> </Label> <Button Content="X" /> </StackPanel>你得到 :
如果你在Window或UserControl中有这个(而不是资源字典),你可以连接它以便点击可以触发,然后你可以从数据绑定集合或直接从TabControl中删除该项目.
我正在使用引导验证程序,但电子邮件字段接受“test@test”。你可以在我的链接上尝试一下。我该如何解决这个问题?使用模式属性,我可以编写正则表达式,但我不知道这样做。
我已经尝试过这个正则表达式,但所有电子邮件都不正确:
<?php
echo $this->tag->emailField(
array(
"email",
"class" => "form-control",
"data-error" => "incorrect address",
"pattern" => '/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i',
"required" => "required"
)
);
?>
Run Code Online (Sandbox Code Playgroud) c# ×4
jasmine ×2
karma-runner ×2
wpf ×2
.net ×1
.net-3.5 ×1
angular ×1
angularjs ×1
c#-4.0 ×1
css ×1
dependencies ×1
forms ×1
getfiles ×1
ionic3 ×1
javascript ×1
nuget ×1
nuspec ×1
phantomjs ×1
styling ×1
textarea ×1
unauthorized ×1
unit-testing ×1
validation ×1
wpf-controls ×1
xaml ×1