所以我有一个像这样的UNC路径:
\\server\folder
Run Code Online (Sandbox Code Playgroud)
我想获得服务器的路径,例如\\server.
Split-Path "\\server\folder" -Parent回报"".我尝试处理root的任何东西都失败了.例如,也Get-Item "\\server"失败了.
我怎样才能安全到达的路径\\server,从\\server\\folderPowerShell中的?
在带有Web API的MVC 5上,我有以下内容,仅使用属性路由:
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
RouteTable.Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.([iI][cC][oO]|[gG][iI][fF])(/.*)?" }); // TODO: Check for Apple Icons
RouteTable.Routes.MapMvcAttributeRoutes();
GlobalConfiguration.Configuration.MapHttpAttributeRoutes();
AreaRegistration.RegisterAllAreas();
Run Code Online (Sandbox Code Playgroud)
在RouteTable中创建了所有MVC路由......但不是API那些......
我检查了RouteTable.Routes,我看到了一个异常:
该对象尚未初始化.确保在所有其他初始化代码之后在应用程序的启动代码中调用HttpConfiguration.EnsureInitialized().
System.Web中的System.Web.Http.Routing.RouteCollectionRoute.get_SubRoutes()at System.Web.Http.Routing.RouteCollectionRoute.GetEnumerator()at System.Linq.SystemCore_EnumerableDebugView`1.get_Items()
为了测试这个,我只为项目添加了两个Web Api动作:
[RoutePrefix("api")]
public class StatApiController : ApiController {
[Route("stats/notescreateddaily"), HttpGet]
public IHttpActionResult NotesCreatedDaily() {
// Some code
}
[Route("stats/userscreateddaily"), HttpGet]
public IHttpActionResult UsersCreatedDaily() {
// Some code
}
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
谢谢你,米格尔
在一个web文档(http://example.com/bla.php?x=123&y=321)中,是否可以创建一个锚链接,而http://example.com/bla.php?z=111不会放入bla.php锚点href?
在我的C#应用程序中,我有以下方法在主窗体关闭时调用.
private void FormMain_Closing(object sender, FormClosingEventArgs e)
{
// Show this dialog when the user tries to close the main form
Form testForm = new FormTest();
testForm.StartPosition = FormStartPosition.CenterParent;
testForm.ShowDialog();
}
Run Code Online (Sandbox Code Playgroud)
这将创建一个对话框窗口,显示主窗体何时关闭.但是,我的问题是当用户关闭时testForm,主表单会立即关闭.我已经尝试过各种各样的变种e.Cancel = true;等等,但仍然无法取消关闭的主要表格.
有任何想法吗?
编辑:看起来我正在使用两个ShowModal()连续的问题.调查问题......
编辑:使用this.DialogResult = DialogResult.None;它似乎解决了我的问题.当从模式对话框打开模态对话框时,它显然是WinForms中的已知问题.
日期存储在DB中,如日期时间字段中的"2011-05-26 11:00:00".我想找到日期大于本月第一天的所有行,即:2011-05-01 09:00:00
DB中的日期格式无法更改.我可以用什么MySQL函数将DB中的日期转换为可以处理比较的格式?我猜测"本月第一"的最佳格式是unix时间戳?
日期中的时间值始终存在,但仅限于办公时间,因此从09:00到17:00.
我已经做了很多次这样做了.
我发现的每一个例子都是我所拥有的......
我查询...
var result = from u in tdc.tblUsers
where u.UserID == userID
select u;
Run Code Online (Sandbox Code Playgroud)
然后我改变我想要的值:
foreach (tblUsers u in result)
{
//change values (and no im not changing the primary key or foreign keys)
}
Run Code Online (Sandbox Code Playgroud)
然后我提交更改
tdc.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)
我之前也尝试过这种方式并得到同样的错误
tblUsers result = (from u in tdc.tblUsers
where u.UserID == userID
select u).Single();
result.Address = address;
result.Phone = phone;
tdc.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)
它只会使用此查询检索1条记录,因为ChangeConflictException它是主键.
当它命中提交更改时,它会抛出未找到或已更改行的异常.我是唯一一个使用它的人,因此访问数据库或锁定没有其他冲突.它为什么会抛出UserID?我已经使用调试器,数据一直持续整个过程,包括我正在尝试进行的更改.
对于某些脚本,我需要有一个由计算属性组成的输出.
例如,对于ip.txt中的ip地址列表,我想知道它们是否响应ping.所以我尝试以下命令:
Get-Content .\ip.txt | Select-Object $_,@{Name="ping?";Expression={Test-Connection $_ -Quiet -Count 1}}
Run Code Online (Sandbox Code Playgroud)
但是我得到一个错误,不管我在scriptblock表达式中做了什么.
错误(法语,抱歉):
Select-Object : Paramètre Null. Le type attendu doit être l'un des suivants : {System.String, System.Management.Automation.ScriptBlock}.
Au niveau de ligne : 1 Caractère : 37
+ Get-Content .\ip.txt | Select-Object <<<< $_,@{Name="ping?";Expression={Test-Connection $_ -Quiet -Count 1}}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
我以前在一些脚本中使用了"计算属性",但是使用了目录对象.为什么它不能用于字符串?
我们正在从一个客户端获取一个 Excel 文件,该文件打开了开放保护和写保留保护。我想删除保护,以便我可以使用 python xlrd 模块打开 Excel 文件。我已经安装了 pywin32 包来通过 COM 访问 Excel 文件,我可以用我的程序打开它,提供两个密码,保存并关闭文件,没有错误。我正在使用 MSDN 网络中描述的 Unprotect 命令,它们没有失败,但它们也没有取消保护。在我的程序完成后,保存的文件仍然需要两个密码才能打开它。这是我到目前为止所拥有的:
import os, sys
impdir = "\\\\xxx.x.xx.x\\allshare\\IT\\NewBusiness\\Python_Dev\\import\\"
sys.path.append(impdir)
from UsefulFunctions import *
import win32com.client
wkgdir = pjoin(nbShare, 'NorthLake\\_testing')
filename = getFilename(wkgdir, '*Collections*.xls*')
xcl = win32com.client.Dispatch('Excel.Application')
xcl.visible = True
pw_str = raw_input("Enter password: ")
try:
wb = xcl.workbooks.open(filename, 0, False, None, pw_str, pw_str)
except Exception as e:
print "Error:", str(e)
sys.exit()
wb.Unprotect(pw_str)
wb.UnprotectSharing(pw_str)
wb.Save()
xcl.Quit()
Run Code Online (Sandbox Code Playgroud)
任何人都可以为我提供有效的取消保护命令的正确语法吗?
我有:
class Parent {}
class Child1 extends Parent{}
class Child2 extends Parent{}
我在我的应用程序中到处使用所有三个类(尤其是子类).现在决定应该删除子类,而父类需要从两个子类中保存字段(和方法).我怎样才能轻松获得所需的结果?
我想到的只是将所有子数据移动到Parent类,然后Ctrl+Shift+R替换所有出现的旧类.我仍然想知道,有没有更好的方法来实现这一目标?
c# ×2
powershell ×2
asp.net-mvc ×1
com ×1
excel ×1
forms ×1
html ×1
iframe ×1
java ×1
linq-to-sql ×1
merge ×1
mysql ×1
path ×1
python ×1
pywin32 ×1
query-string ×1
string ×1
unc ×1