我正在尝试上传一个非常大的XML文件(大约1 gig),该文件将被解析为字符串,以便可以将其处理为可以在数据库中使用的格式。我已经完成了字符串操作部分以及所有其他方面的工作。问题是我相信
"WorkbookXML = System.IO.File.ReadAllText(outputPath);"
使用StringBuilder作为依赖项,它具有默认集MaxValueProperty,在我尝试上传文件时会被超出,因此引发异常。如何设置此变量的MaxValueProperty?
public void ScoutXMLFileProcess(HttpPostedFile fl, string uniqueName)
{
try
{
outputPath = ConfigurationManager.AppSettings["FileServer"] +
"\\CustomerUploadedFiles\\" + db.DatabaseName + "\\Integration\\";
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
string fName = fl.FileName;
if (fName.IndexOf("\\") != -1) { fName =
fName.Substring(fName.LastIndexOf("\\") + 1); }
string fileDataLink = uniqueName + Path.GetExtension(fName);
outputPath += fileDataLink;
fl.SaveAs(outputPath);
transactionTypeID = Convert.ToInt32(Request["textInput"]);
integrationTypeDt =
DAC.ExecuteDataSetText(db.ConnectionString, "SELECT [StoredProcName],
[Configuration] FROM [dbo].[ITransactionType] WITH(NOLOCK) WHERE
[TransactionTypeID] =" + transactionTypeID, new string[] {
"IntegrationType" }).Tables[0];
```
string workbookXML = System.IO.File.ReadAllText(outputPath);
```
int pFrom = workbookXML.IndexOf("<SaveDataFromScout>");
int pToo = workbookXML.IndexOf("</SaveDataFromScout>") + 20;
workbookXML = workbookXML.Substring(pFrom, pToo - pFrom);
workbookXML = workbookXML.Replace("\r\n", "");
workbookXML = Regex.Unescape(workbookXML);
我收到指出
的异常错误System.OutOfMemoryException:引发了类型为'System.OutOfMemoryException'的异常。在System.IO.File.InternalReadAllText(字符串路径,编码编码,布尔值CheckHost)在System.IO.File.ReadAllText(字符串路径)在System.IO.StreamReader.ReadToEnd()在System.Text.StringBuilder.ToString()在C:\ Users \ jp171 \ Source \ Repos \ CaseWorthy \ CaseWorthy \ CaseWorthy \ UploadIntegrationExcel.aspx.cs:line 240
中的CaseWorthy.UploadIntegrationExcel.ScoutXMLFileProcess(HttpPostedFile fl,String uniqueName)第240行是workbookXML所在的位置。
我期望它能够处理并将大型XML文件保存到输出路径位置。