这是我读取文件的方式:
public static string readFile(string path)
{
StringBuilder stringFromFile = new StringBuilder();
StreamReader SR;
string S;
SR = File.OpenText(path);
S = SR.ReadLine();
while (S != null)
{
stringFromFile.Append(SR.ReadLine());
}
SR.Close();
return stringFromFile.ToString();
}
Run Code Online (Sandbox Code Playgroud)
问题是这么久(.txt文件大约是2.5兆).花了5分多钟.有没有更好的办法?
解决方案
public static string readFile(string path)
{
return File.ReadAllText(path);
}
Run Code Online (Sandbox Code Playgroud)
花了不到1秒...... :)
你怎么分裂一个字符串?
可以说我有一个字符串"狗,猫,老鼠,鸟"
我的实际目标是将每个动物插入一个listBox,这样它们就会成为列表框中的项目.
但我想如果我知道如何分割字符串,我会知道如何插入这些项目.还是有人知道更好的方法吗?
即时通讯使用asp c#
网格正确显示所有信息,在事件dataGridView1cellFormatting中,我根据线值下的对象改变背景颜色.这也有效.我在网格上的最后一个事件是dataGridView1_CellPainting,它检查它是否是添加图标的标题.
一切都很好,直到我尝试取出所选行的颜色(或单元格做同样的事情).我想要的是取出所选行的颜色.我试图用"透明"设置它,但是当控件绑定数据时,该行是灰色的,当我们调整列大小时,文本是不可读的.
如何在不突出显示所选行的情况下在DataGridView中显示数据?
像这样的工具如何能够将ajax风格的调用回到中心站点?基本上他们会给你一个"标记放在你的网站上.所以在这个小部件中,你有能力要求发送一封电子邮件给你当前的页面.我认为这是一个ajax样式回叫分享这个发送电子邮件的人.但他们怎么能在你的服务器上没有代理服务器而没有浏览器阻止它作为XSS漏洞呢?
非常感谢您的帮助,谢谢您的帮助.我假设使用Flickr API会带来同样的挑战吗?
标题链接:http://sharethis.com/
如果你有一个被描述为C结构的二进制文件格式(或数据包格式),是否有任何程序可以解析结构并将其转换为协议的简洁文档?
结构当然包含数组,其他结构等,以描述格式.文档可能需要包含诸如打包,字节顺序等内容.
我有一个包含字符串的文本框,只有当用户按下按钮时才必须绑定该字符串.在XAML中:
<Button Command="{Binding Path=PingCommand}" Click="Button_Click">Go</Button>
<TextBox x:Name="txtUrl" Text="{Binding Path=Url,UpdateSourceTrigger=Explicit, Mode=OneWay}" />
Run Code Online (Sandbox Code Playgroud)
在代码隐藏中:
private void Button_Click(object sender, RoutedEventArgs e)
{
BindingExpression be = this.txtUrl.GetBindingExpression(TextBox.TextProperty);
be.UpdateTarget();
}
Run Code Online (Sandbox Code Playgroud)
"be"始终为NULL.为什么?
更新:
好的,这是经过大量尝试后的一些更新.
如果,我将模式OneWay设置为显式更新.我在GetBindingExpression的"be"对象中有一个NullReferenceException.
如果我使用显式更新将模式设置为空(默认为TwoWay).我有绑定获取值(string.empty)并且它每次都会删除文本框中的所有内容.
如果我将Mode设置为OneWay,使用PropertyChanged当我按下文本框中的键时,绑定的属性没有任何内容,当我单击按钮时,我在"be"对象中有一个NULLReferenceException.
如果我将模式设置为空(默认为TwoWay),使用PropertyChanged我每次按(GOOD)时都会提高属性但我不希望每次用户按键时都更改属性...但只有一次用户按下按钮.
我可以使用以下URL直接将webservie调用到浏览器,它将返回我想要的所有内容:
http://localhost:64438/MySearchAutoComplete.asmx/GetCompletionList
Run Code Online (Sandbox Code Playgroud)
当我将它添加到autocompleteexetender到Default.aspx页面时,如下所示:
<cc1:AutoCompleteExtender ID="AutoCompleteExtender1"
TargetControlID="TextBox1"
runat="server"
ServiceMethod="GetCompletionList"
ServicePath="http://localhost:64438/MySearchAutoComplete.asmx"
CompletionSetCount="12"
MinimumPrefixLength="1" />
Run Code Online (Sandbox Code Playgroud)
页面加载,我有一个文本框但每次在文本框中添加击键时我都有一个错误500.我在FireFox FireBug中看到了错误.
http://localhost:62702/ --->This is the webpage that load fine
Run Code Online (Sandbox Code Playgroud)
alt text http://clip2net.com/clip/m12122/1269451120-clip-2kb.png - >这是错误
任何的想法?我注意到我需要附加调试webservice的过程,我也可能做错了吗?
如果我去我的机器的事件查看器.我可以看到 :
Exception information:
Exception type: InvalidOperationException
Exception message: Request format is unrecognized for URL unexpectedly ending in '/GetCompletionList'.
Thread information:
Thread ID: 8
Thread account name: MTL\daok
Is impersonating: False
Stack trace: at System.Web.Services.Protocols.WebServiceHandlerFactory.CoreGetHandler(Type type, HttpContext context, HttpRequest request, HttpResponse response)
at System.Web.Services.Protocols.WebServiceHandlerFactory.GetHandler(HttpContext context, String verb, String url, String filePath) …Run Code Online (Sandbox Code Playgroud) <?xml version="1.0" encoding="utf-8"?>
<xs:schema id="abc" targetNamespace="http://schemas.businessNameHere.com/SoftwareNameHere"
elementFormDefault="qualified"
xmlns="http://schemas.businessNameHere.com/SoftwareNameHere"
xmlns:mstns="http://schemas.businessNameHere.com/SoftwareNameHere"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="..." type="..." />
<xs:complexType name="...">
Run Code Online (Sandbox Code Playgroud)
我正在使用XSD生成.cs文件的项目.我的问题是关于字符串" http://schemas.businessNameHere.com/SoftwareNameHere "如果我改变它,它不起作用.但是http://不是一个有效的......背后的逻辑是什么,我在哪里可以获得有关放在那里或如何更改它的信息?
我用Northwind数据库做了一个小项目来说明问题所在.
这是控制器的动作:
[HttpPost]
public ActionResult Edit(Product productFromForm)
{
try
{
context.Products.Attach(productFromForm);
var fromBD = context.Categories.Find(productFromForm.Category.CategoryID);
productFromForm.Category = fromBD;
context.Entry(productFromForm).State = EntityState.Modified;
context.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
context在Controller的构造函数中实例化new DatabaseContext().
public class DatabaseContext:DbContext
{
public DatabaseContext()
: base("ApplicationServices") {
base.Configuration.ProxyCreationEnabled = false;
base.Configuration.LazyLoadingEnabled = false;
}
public DbSet<Product> Products { get; set; }
public DbSet<Category> Categories { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder){
modelBuilder.Configurations.Add(new ProductConfiguration());
modelBuilder.Configurations.Add(new CategoriesConfiguration());
}
private class ProductConfiguration : EntityTypeConfiguration<Product> …Run Code Online (Sandbox Code Playgroud) c# asp.net-mvc entity-framework asp.net-mvc-3 entity-framework-4.3
c# ×7
asp.net ×3
.net ×2
.net-2.0 ×1
ajax ×1
asp.net-ajax ×1
asp.net-mvc ×1
binding ×1
c ×1
datagridview ×1
exploit ×1
io ×1
listbox ×1
optimization ×1
php ×1
string ×1
struct ×1
web-services ×1
winforms ×1
wpf ×1
xsd ×1
xss ×1