Tag: asp.net 4.0

什么是File.Open的默认目录?

我有这个代码: Stream f = File.Open(“data.majid”, FileMode.OpenOrCreate, FileAccess.ReadWrite); 文件创建在哪里?

将匿名类型转换为DataTable

将匿名类型转换为DataTable的最快方法是什么? 更新:我想从匿名类型获取并填充DataTable。 如果reflection是必要的,我怎么能用reflection来做呢?

使用File.Copy移动文件或将流写入该位置有什么区别吗?

我正在重构一些代码,有一个问题,我可以使用一些评论。 原始代码将文件下载到流中。 然后,在使用File.Copy覆盖生产目录中的现有文件之前,它会将流写入临时目录中的File。 将它写入temp目录并使用File.Copy与仅将流写入生产目录相比,是否有任何好处? 一个原因可能是File.Copy比写入流更快,并且减少了某人在写入文件时读取文件的机会。 但这甚至会发生吗? 我还应该记住什么? 我正在考虑将temp目录分解出来。 MemoryStream stream = new MemoryStream(); ….Download and valiate stream…. using (Stream sourceFileStream = stream) { using (FileStream targetFileStream = new FileStream(tempPath, FileMode.CreateNew)) { const int bufferSize = 8192; byte[] buffer = new byte[bufferSize]; while (true) { int read = sourceFileStream.Read(buffer, 0, bufferSize); targetFileStream.Write(buffer, 0, read); if (read […]

从SQL查询中获取参数名称

后端是PostgreSQL服务器9.1。 我正在尝试构建AdHoc XML报告。 报告文件将包含SQL查询,所有这些查询都必须以SELECT语句开头。 SQL查询将包含参数。 根据相关列的数据类型,这些参数将相应地呈现给用户以提供值。 一个重要的SQL查询: SELECT * FROM customers WHERE ( customers.customer_code=@customer_code AND customers.location=@location AND customers.type= ( SELECT type from types WHERE types.code=@type_code AND types.is_active = @type_is_active ) AND customers.account_open_date BETWEEN @start_date AND @end_date ) OR customers.flagged = @flagged; 我想从查询字符串中获取列名和参数的列表,并将它们放入字符串数组中并稍后处理。 我能够使用以下正则表达式仅匹配参数: @(?)(?\w+) 预期比赛: customers.customer_code=@customer_code customers.location=@location types.code=@type_code types.is_active = @type_is_active customers.account_open_date BETWEEN @start_date AND […]

将模型从一个动作传递到同一控制器中的另一个动作

我试图将我的模型List statementList从一个动作传递到另一个动作,但我在第二个控制器中接收空值。 请在这里建议有什么问题。 甚至试过: return RedirectToAction(“WriteInTemplate”, new { statementList = statementList }); 请帮忙。 public ActionResult SendPdfStatement(string InvoiceNumber) { try { InvoiceNumber = InvoiceNumber.Trim(); ObjectParameter[] parameters = new ObjectParameter[1]; parameters[0] = new ObjectParameter(“InvoiceNumber”, InvoiceNumber); List statementList = new List(); statementList = _db.ExecuteFunction(“uspInvoiceStatement”, parameters).ToList(); //WriteInTemplate(statementList); return RedirectToAction(“WriteInTemplate”, statementList ); } catch (Exception e) { InvoiceSearchTool.Models.udtExceptionTable exception = […]

强制配置在wcf客户端c#中使用tls 1.0

我们有一个Web应用程序,其客户端使用WCF实现。 此客户端使用SSL_LVL3与外部服务进行握手。 事实certificate该服务刚刚禁用了SSL_LVL3,因此我们需要将其更改为TLS 1.0。 有一种方法可以强制C#中的TLS安全性: ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls; 但它会改变应用程序使用的所有服务的安全性,而不是所有服务都接受TLS。 我们想要的是更改web.config以强制WCF服务使用TLS。 有没有办法做到这一点? 这是服务的绑定:

想要将字面值访问到javascript中

我在页面上有一个文字控件(有一些数据)。 我想在javascript中访问它,并希望在其上放置一些文本。 请告诉我如何在JavaScript中访问文字控件。 我正在尝试使用以下代码 – 使用Javascript: var value= document.getElementById(”) 我得到null值返回。

从其他服务器访问图像

我将图像文件放在一台服务器上,将应用程序放在其他服务器上。 我想访问该图像,在我编写的代码下面: 在default.aspx上,我有 在GetImage.aspx上,我在page_load上编写了以下代码 protected void Page_Load(object sender, EventArgs e) { // Changing the page’s content type to indicate the page is returning an image Response.ContentType = “image/jpg”; var imageName = Request.QueryString[“imgName”]; var path = “//SERVER/FOLDER/” + imageName; if ((string.IsNullOrEmpty(imageName) == false)) { // Retrieving the image System.Drawing.Image fullSizeImg; fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(path)); // Writing the […]

如何将对象列表发送到WCF服务?

我正在构建WCF服务,我想接受List作为我的方法之一的参数。 这是我的代码: [ServiceContract] public interface IProductService { [OperationContract] int InsertProducts(List products); } [DataContract] [KnownType(typeof(List))] public class Product { [DataMember] public int ProductId{ get; set; } [DataMember] public string ProductName{ get; set; } [DataMember] public List Products { get; set; } } 当我运行服务时,它给了我一个错误。 WCF不支持此操作,因为它使用NameSpace.Product[]

在ASP.Net中的运行时按名称隐藏GridView列

是否可以在运行时按名称显示/隐藏GridView列? 我可以通过索引来完成,如下所示: gridReviews.Columns[4].Visible = false; 但是我想做以下事情: gridReviews.Columns[“Name”].Visible = false; 最好的方法是什么?