有没有人知道如何使用package.Saveas函数?
package.SaveAs(tempFolderPathAlt + saveas + ".xlsx");
Run Code Online (Sandbox Code Playgroud)
此时以红色下划线标出以下错误:
'OfficeOpenXml.ExcelPackage.SaveAs(System.IO.Stream)'的最佳重载方法匹配有一些无效的参数
目前我正在以下列方式保存文件.
FileStream aFile = new FileStream(tempFolderPathAlt + saveas + ".xls", FileMode.Create);
byte[] byData = package.GetAsByteArray();
aFile.Seek(0, SeekOrigin.Begin);
aFile.Write(byData, 0, byData.Length);
aFile.Close();
Run Code Online (Sandbox Code Playgroud)
但是这种方式包仍然是开放的,我不能使用它使用的文件.
save as将正确关闭包,但它不接受我的文件路径.
编辑
我试过这个:
using (FileStream aFile = new FileStream(tempFolderPathAlt + saveas + ".xlsx", FileMode.Create))
{
byte[] byData = package.GetAsByteArray();
aFile.Seek(0, SeekOrigin.Begin);
package.SaveAs(aFile);
//aFile.Write(byData, 0, byData.Length);
aFile.Close();
}
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误?
包对象已关闭并处理,因此无法对此对象或此包的一部分上打开的任何流执行操作.
我有一个XML文件,我想迭代每个子节点收集信息.
这是我的C#代码,它只选择一个节点,FieldData我想在其子节点上使用foreach.
public void LoadXML() {
if (File.Exists("Data.xml")) {
//Reading XML
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Data.xml");
//Think something needs to reference Child nodes, so i may Foreach though them
XmlNodeList dataNodes = xmlDoc.SelectNodes("//FieldData");
TagContents[] ArrayNode;
foreach(XmlNode node in dataNodes) {
int Count = 0;
//int Max = node.ChildNodes.Count;
ArrayNode = new TagContents[Max];
ArrayNode[Count].TagName = node.Name;
ArrayNode[Count].TagValue = node.SelectSingleNode(ArrayNode[Count].TagName).InnerText;
Count = Count + 1;
}
} else {
MessageBox.Show("Could not find file Data.xml");
}
}
Run Code Online (Sandbox Code Playgroud)
我的XML看起来像:
<?xml version="1.0"?>
<FieldData>
<property_details_branch …Run Code Online (Sandbox Code Playgroud) 我想从异步任务返回一个字符串结果.
System.Threading.Tasks.Task.Run(async () => await audatex.UploadInvoice(assessment, fileName));
public async Task UploadInvoice(string assessment, string fileName)
{
//Do stuff
return string;
}
Run Code Online (Sandbox Code Playgroud)
异步编程困惑我,有人可以解释一下吗?
我创建了一个数据库emailDatabase,它存储在
C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Run Code Online (Sandbox Code Playgroud)
在Visual Studio中,我使用Server Explorer,单击添加新连接按钮.
将出现"添加连接"对话框.
在服务器名称下,我使用下拉框并选择DEV-5\SQLEXPRESS.我使用Windows身份验证.
在Connect to底部的部分中,下拉列表显示:Master, Model, msdb并且tempdb不显示我的emailDatabase.
所以我选择Attach Database File并单击浏览并关注
local C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA
Run Code Online (Sandbox Code Playgroud)
并选择我的电子邮件数据库
发生以下错误:
emailDatabase
您无权打开此文件.
联系文件所有者或管理员以获取权限.
我认为我的问题是我保存了我的数据库错误,我需要备份或类似的东西.如果是这种情况请告诉我如何备份等等.我真的需要从这个问题前进.
当我创建我的数据库时,我右键单击SQL Server Management Studio中的数据库并说新数据库,然后我添加了带有查询的列.然后文件保存所有.
如何获取我的数据库文件的副本,其中包含我在Visual Studio中使用它所需的所有权限?
database sql-server visual-studio-2010 sql-server-2008 visual-studio
我正在尝试使用State Server会话.
我已将会话状态更改为以下内容:
<sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" cookieless="false" timeout="20" />
Run Code Online (Sandbox Code Playgroud)
从本地主机运行我的网站,一切正常.
但是,当我发布我的网站并尝试在线运行时,我收到以下错误:
无法向会话状态服务器发出会话状态请求.请确保已启动ASP.NET状态服务,并且客户端和服务器端口是相同的.如果服务器位于远程计算机上,请通过检查HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection的值来确保它接受远程请求.如果服务器位于本地计算机上,并且前面提到的注册表值不存在或设置为0,则状态服务器连接字符串必须使用"localhost"或"127.0.0.1"作为服务器名称.
该网站托管在Afrihost服务器上,在重新分析错误后我发现它可能是因为ASP.NET状态服务尚未启动.有没有办法可以检查Afrihost服务器是运行此服务还是远程启动它?
另外我知道IP地址127.0.0.1适用于本地主机,但是因为您在Web服务器上发布应用程序,所以它成为本地机器是正确的.
我创建了一个Web电子邮件应用程序,如何查看和保存附件?
我正在使用OpenPop,第三方dll,我可以发送带附件的电子邮件和阅读没有附件的电子邮件.
这很好用:
Pop3Client pop3Client = (Pop3Client)Session["Pop3Client"]; // Creating newPopClient
int messageNumber = int.Parse(Request.QueryString["MessageNumber"]);
Message message = pop3Client.GetMessage(messageNumber);
MessagePart messagePart = message.MessagePart.MessageParts[1];
lblFrom.Text = message.Headers.From.Address; // Writeing message.
lblSubject.Text = message.Headers.Subject;
lblBody.Text=messagePart.BodyEncoding.GetString(messagePart.Body);
Run Code Online (Sandbox Code Playgroud)
第二部分代码显示了附件的内容,但只有在它是文本文件时才有用.我需要能够保存附件.我在这里的代码的底部部分写了我的消息正文,所以如果我收到一个附件,我无法查看我的消息正文.
if (messagePart.IsAttachment == true) {
foreach (MessagePart attachment in message.FindAllAttachments()) {
if (attachment.FileName.Equals("blabla.pdf")) { // Save the raw bytes to a file
File.WriteAllBytes(attachment.FileName, attachment.Body); //overwrites MessagePart.Body with attachment
}
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用我的C#应用程序将图片插入Excel Spread Sheet.
我使用以下作为我的来源.http://csharp.net-informations.com/excel/csharp-insert-picture-excel.htm
整条线用蓝色下划线标出.
xlWorkSheet.Shapes.AddPicture("C:\\pic.JPG", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45);
Run Code Online (Sandbox Code Playgroud)
我的代码:
private void btnWriteSpreedSheet_Click(object sender, EventArgs e)
{
Excel.Application xlApp;
Excel.Workbook xlWorkBook;
Excel.Worksheet xlWorkSheet;
object misValue = System.Reflection.Missing.Value;
xlApp = new Excel.ApplicationClass();
xlWorkBook = xlApp.Workbooks.Add(misValue);
xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
//xlWorkSheet.SetBackgroundPicture("C:/Users/Shaun/Documents/Visual Studio 2010/Projects/TestXMLToEXCEL/TestXMLToEXCEL/bin/Debugpic.JPG"); //
//add some text
xlWorkSheet.Cells[1, 1] = "http://csharp.net-informations.com";
xlWorkSheet.Cells[2, 1] = "Adding picture in Excel File";
xlWorkSheet.Shapes.AddPicture("C:\\pic.JPG", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, 50, 50, 300, 45); //C:\\csharp-xl-picture.JPG
xlWorkBook.SaveAs("csharp.net-informations.xls", Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); …Run Code Online (Sandbox Code Playgroud) 我试图使用一个会话,但当我需要值返回其null?
我的网站以登录开始,我将用户名放入会话.
Session["userName"] = login.UserName;
Run Code Online (Sandbox Code Playgroud)
然后该网站被重定向到新页面.
return RedirectToAction("Choice", new { token = token });
Run Code Online (Sandbox Code Playgroud)
巫婆之后我使用链接移动到我的下一页.
@Html.ActionLink("Download", "Download", new {token = Model.Token})
Run Code Online (Sandbox Code Playgroud)
我将我的代码指向家庭控制器中的动作结果,同一个控制器我有我的登录功能.
@Html.ActionLink("Download", "DownloadFile", new { fileid = item.Key, token = Model.Token, platform = "windows", filename = item.Value }, new {@class = "DownloadLink" } )
Run Code Online (Sandbox Code Playgroud)
我尝试再次调用我的会话值.
formMobiApi.GetFile(token, fileid, platform, filename, Session["userName"].ToString(), tasks, taskId, spreadSheetStatus);
Run Code Online (Sandbox Code Playgroud)
这些操作中的任何一个是否都可以使我的会话值为null?
我可以使用这样的会话吗?
我正在尝试重定向到视图并继续在问题标题中发布错误.
在断点测试期间,通过代码iv的第一位的代码放在设置消息和设置异常之下.在返回重定向后继续显示下一页显示如下.

向ErrorController和错误模型添加断点我发现代码永远不会到达那里.
我想要发布的视图是一个错误页面.这是代码,以帮助您看到问题.
RedirectToAction:
string message;
message = "An error has occured during the communication to lightstone, this is likely a timeout issue and could be the result of a bad connection. Please go back and try again.";
return RedirectToAction("Error", "Error", new { ex = ex.ToString(), message = message});
Run Code Online (Sandbox Code Playgroud)
我的ErrorController中的操作:
public ActionResult Error(string ex, string message)
{
ViewBag.Message = "Error";
return View(new ErrorModel(ex, message));
}
Run Code Online (Sandbox Code Playgroud)
我的错误模型:
namespace MvcResComm.Models
{
public class ErrorModel
{
public string ex { get; set; …Run Code Online (Sandbox Code Playgroud) 我试图通过Url.Action发送多个参数.
$('#dialog').dialog({
autoOpen: false,
width: 850,
height: 420,
resizable: false,
title: 'Vehicle details',
modal: true,
open: function (event, ui) {
$(this).load("@Url.Action("LightStoneRequest", new { registrationNumber = Model.VehicleRegistration, vinNumber = Model.vVinNumber })");
},
buttons: {
"Close": function () {
$(this).dialog("close");
}
}
});
Run Code Online (Sandbox Code Playgroud)
在运行时,它看起来如下:
$(this).load("/APQuotes/LightStoneRequest?registrationNumber=TE5TGP&vinNumber=VINTEST44889856");
Run Code Online (Sandbox Code Playgroud)
正如你所看到的,有一个vin号通过,但它在我的控制器中为null.
这是我的模态.
public partial class LightStoneRequest
{
public LightStoneRequest()
{
this.LightStoneDataFields = new HashSet<LightStoneDataField>();
}
public int LightStoneRequestId { get; set; }
public string RegistrationNumber { get; set; }
public string VinNumber { get; set; }
public …Run Code Online (Sandbox Code Playgroud) c# ×6
asp.net ×3
session ×2
asp.net-mvc ×1
async-await ×1
attachment ×1
database ×1
email ×1
epplus ×1
excel ×1
openpop ×1
save ×1
sql-server ×1
stateserver ×1
url ×1
url.action ×1
web-hosting ×1
xml ×1