我需要将CSV转换为XML文档.到目前为止我看到的示例都显示了如何使用CSV中的固定数量的列进行此操作.
到目前为止,我使用LINQ:
String[] File = File.ReadAllLines(@"C:\text.csv");
String xml = "";
XElement top = new XElement("TopElement",
from items in File
let fields = items.Split(';')
select new XElement("Item",
new XElement("Column1", fields[0]),
new XElement("Column2", fields[1]),
new XElement("Column3", fields[2]),
new XElement("Column4", fields[3]),
new XElement("Column5", fields[4])
)
);
File.WriteAllText(@"C:\xmlout.xml", xml + top.ToString());
Run Code Online (Sandbox Code Playgroud)
这适用于固定数量的列,但我的.CSV在每行上具有不同的列数.
根据.CSV每行中有多少单词(列),你会如何适应某种循环呢?
日Thnx
哇,很难找到这个主题的简单解释.一个简单的多对多关系.
三个表,tableA,tableB和一个联结表A_B.
我知道如何使用密钥和所有设置关系,但是当执行INSERT,UPDATE和DELETE查询时,我会感到有些困惑....
基本上,我正在寻找的是一个示例,显示:
如何根据TableB中的ID获取TableA中的所有记录
如何根据TableA中的ID获取TableB中的所有记录
3如何在TableA或TableB中插入,然后在联结表中进行相应的INSERT以建立连接.
我不是在寻找特定项目的解决方案,只是可以应用的一些常规示例.也许你有什么东西躺在身边?
我创建了一个小类库,其中一个HttpModule使用过滤器为IIS7提供的每个请求页面添加一些html.
我首先通过在测试网站中的web.config中注册模块来测试它,它可以正常工作,但只能在那个应用程序中运行.
我生成了一个dll,并创建了一个强大的命名程序集.
我需要以某种方式将此程序集作为一个模块添加到服务器级别的IIS中,以便它适用于所有请求,所有应用程序以及nonasp.net内容.
到目前为止,我已尝试将.dll添加为本机模块.这不起作用.它位于本机模块列表中,但不起作用.
我在GAC中安装了.dll.
继续阅读,似乎我必须将程序集添加为托管模块,然后在IIS中的"添加托管模块"下的下拉列表中选择它.
为此,我尝试使用命令行工具appcmd,写道:"add module/name:string/type:string/preCondition:string"
我没有成功这样做,因为我无法弄清楚要设置什么类型和前提条件.
正如我所读到的,在IIS中注册的模块应该适用于所有站点中的所有应用程序以及所有请求.
关键是要避免在每个应用程序web.config文件中注册该模块.
有任何想法吗?
我需要从一段文本中提取包含url中特定单词的超链接.例;
"这是一个带有某个页面链接的文本.单击此链接<a href="/server/specificword.htm>this is a link to a page</a>可查看该页面.这是一个链接,其中没有"specificword"一词:<a href="/server/mypage.htm>this is a link without the word "specificword" in the url</a>"
因此,我需要解析此文本,检查超链接以查看其中一个是否包含单词"specificword",然后提取整个超链接.然后我会以此结束:
<a href="/server/specificword.htm>this is a link to a page</a>
Run Code Online (Sandbox Code Playgroud)
我需要在网址中具有特定字符的超链接,例如./server/specificword.htm,不在链接文本中
我试过的一个正则表达式就是这个:/(<a[^>]*>.*?</a>)|specificword/
这将匹配文本中的所有超链接,或"特定字".如果文本有多个链接,没有"specificword"这个词,我也会得到这些.
此外,我尝试过这个,但它没有任何结果:
<a.*?href\s*=\s*["\']([^"\'>]*specificword[^"\'>]*)["\'][^>]*>.*?<\/a>
Run Code Online (Sandbox Code Playgroud)
我的正则表达式技巧在这里结束,任何帮助都会很棒....
可能重复:
MVC3 + Ninject - 如何?
在一个小型的mvc 4项目中,我正在尝试使用ninject实现依赖注入.
到目前为止,我已经使用api控制器了,但我对常规控制器没有任何好运.
我有一个NinjectResolver:
public class NinjectDependencyResolver : NinjectDependencyScope, IDependencyResolver
{
private readonly IKernel _kernel;
public NinjectDependencyResolver(IKernel kernel)
: base(kernel)
{
_kernel = kernel;
}
public IDependencyScope BeginScope()
{
return new NinjectDependencyScope(_kernel.BeginBlock());
}
public override void Dispose()
{
_kernel.Dispose();
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个NinjectScope:
public class NinjectDependencyScope : IDependencyScope
{
protected IResolutionRoot ResolutionRoot;
public NinjectDependencyScope(IResolutionRoot kernel)
{
ResolutionRoot = kernel;
}
public object GetService(Type serviceType)
{
var request = ResolutionRoot.CreateRequest(serviceType, null, new Parameter[0], true, true);
return …Run Code Online (Sandbox Code Playgroud) 我有一个我需要动态添加的UserControl.我试着按照这篇MSDN文章,但我没有任何成功.... http://msdn.microsoft.com/en-us/library/c0az2h86.aspx
UserControl基本上是一个图库,它根据ID加载一些图片.我的想法是将此ID作为属性提供.然后,当我创建控件的实例时,我可以设置此ID并将其添加到表单中.
我在.aspx页面中添加了对将使用它的控件的引用,如下所示:
<%@ Reference Control="~/PictureGallery.ascx" %>
Run Code Online (Sandbox Code Playgroud)
在UserControl中我添加了一个类似这样的ClassName:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PictureGallery.ascx.cs"
Inherits="PictureGallery" ClassName="PictureGallery" %>
Run Code Online (Sandbox Code Playgroud)
当我尝试在文章建议的.aspx.cs中创建一个实例时Dim gallery As ASP.PictureGallery,我得到一个"类型ASP.PictureGallery未定义".
文章提到了一个命名空间,ASP我尝试将它导入.aspx.cs,但没有运气.所以,我无法获得对UserControl的引用.
怎么修好?
我需要通过使用jQuery调用PageMethod来设置几个Session var。
客户端js看起来像这样:
function setSession(Amount, Item_nr) {
//alert(Amount + " " + Item_nr);
var args = {
amount: Amount, item_nr: Item_nr
}
//alert(JSON.stringify(passingArguments));
$.ajax({
type: "POST",
url: "buycredit.aspx/SetSession",
data: JSON.stringify(args),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert('Success.');
},
error: function () {
alert("Fail");
}
});
}
Run Code Online (Sandbox Code Playgroud)
和服务器端是这样的:
[System.Web.Services.WebMethod(EnableSession = true)]
public static void SetSession(int amount, int item_nr)
{
HttpContext.Current.Session["amount"] = amount;
HttpContext.Current.Session["item_nr"] = item_nr;
}
Run Code Online (Sandbox Code Playgroud)
只是,似乎没有设置会话变量。当我尝试Response.Write出Session变量时,我什么也没得到。我没有收到任何错误,并且可以警告从onclick事件传递到js函数的值,因此它们就在那。
谁能看到我错过了什么吗?
n
如何在超链接内的文本中添加span标记?
现在,我正在使用以下内容将现有文本更改为其他内容:
$(document).ready(function() {
$("a:contains('text')").text('new-text')
});
Run Code Online (Sandbox Code Playgroud)
解析时我需要链接看起来像这样:
<a href="/xxx.aspx">new-text<span class="someclass">some other text</span></a>
Run Code Online (Sandbox Code Playgroud)
所以我需要在内部添加span标签
有任何想法吗?
我正在使用一些自定义元素设置自定义 RSS 提要。我需要添加一个带有自定义属性的自定义元素。
到目前为止,我已经设置了这样的提要:
var testItem = new SyndicationItem("title", "description", new Uri("http://myuri.com"));
customItem.ElementExtensions.Add("customElement", String.Empty, "fooBar");
Run Code Online (Sandbox Code Playgroud)
将 testItem 添加到名为“items”的列表中,然后:
var feed = new SyndicationFeed("TestFeed", "FeedContent", new Uri("http://myuri.com"), items);
Run Code Online (Sandbox Code Playgroud)
这会产生这样的东西......
<rss>
<channel>
<title>TestFeed</title>
<link>http://myuri.com</link>
<description>FeedContent</description>
<item>
<link>http://myprovider.com/contentid=1234</link>
<title>title</title>
<description>description</description>
<customElement>fooBar</customElement>
</item>
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)
现在,如果我想添加自定义元素,然后向该元素添加自定义属性,该怎么办?
我可以像这样创建一个新的 SyndicateItem:
var customElement = new SyndicationItem();
Run Code Online (Sandbox Code Playgroud)
然后向其添加属性,如下所示:
customElement.AttributeExtensions.Add(new XmlQualifiedName("myAttribute", ""), "someValue");
customElement.AttributeExtensions.Add(new XmlQualifiedName("anotherAttribute"), "someOtherValue");
Run Code Online (Sandbox Code Playgroud)
然后将其添加到我的 testItem 中,使其出现在 rss feed 的项目列表中:
testItem.ElementExtensions.Add(customElement);
Run Code Online (Sandbox Code Playgroud)
编译器吃掉它,但我收到运行时错误,我认为这是因为新元素没有名称。
除此之外,我找不到其他方法来做到这一点
创建提要的 XmlDoc,然后开始向其附加元素和属性。
有必要这样做似乎很奇怪,而且我觉得我一定是监督了一些事情。
有任何想法吗?
asp.net ×3
c# ×3
jquery ×2
csv ×1
httpmodule ×1
iis-7 ×1
many-to-many ×1
ninject ×1
pagemethods ×1
regex ×1
rss ×1
session ×1
xml ×1