How can I convert a uploaded XML file that is in the form of a HttpPostedFIle to a string in C# asp.net? I am trying to create the ability to upload an XML file and store it on a database server for a client that is using my web application. I need to convert it to a string so I can do string manipulation to the XML file and remove some elements in the XML file that are not compatible with SQL server.
I've tried this and a few other things. I keep getting the error
InputStream is not in this current context
and another error.
string xmlString = System.IO.File.ReadAllText(fl.InputStream.ToString());
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 = "";
//load the file,
string xmlString = System.IO.File.ReadAllText(fl.InputStream.ToString());
//make changes
//Assign the file to the XML var,
//and then save it into the database
I expect it to return a string value of the entire file that was uploaded. Instead, I am getting two errors. One says InputStream is not in the current context.