System.IO.Path.GetTempPath() access denied - directory

im creating temporary files to be stored in the Temp folder found by:
string path = System.IO.Path.GetTempPath()
method returns C:\windows\Temp\
i append my filename:
string filename = myfile.txt
System.IO.Path.Combine(path,filename)
However, this gives me a
"Message":"The given path\u0027s format is not supported.","StackTrace":" at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)\r\n at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)\r\n at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)\r\n at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, AccessControlActions...... and so on
I have tried modifying the rights to the TEMP folder, so that NETWORK SERVICES has rights..
Any ideas?

Your path contains an invalid character. Unicode code is 0027 which is a single quote "'" so you need to check where you are adding a single quote to the path.

Related

Unexpected character encountered while parsing value: C. Path '', line 1, position 2

I have a json string which is constructed by the following code:
string path1 = "C:\\Program Files (x86)\\IMAGE\\model\\net.mat";
string path2 = "C:\\Program Files (x86)\\IMAGE\\png\\Lab.png";
string path3 = "D:\\temp\\";
string[] strs={path1 ,path2 ,path3};
string json = JsonConvert.SerializeObject(strs);
Console.WriteLine(json);
List<string> paths = JsonConvert.DeserializeObject<List<string>>(json);
Console.WriteLine(paths.Count);
and there is no error when I serialize it or deserialize it.
The json string is as follows:
"[\"C:\\\\Program Files (x86)\\\\IMAGE\\\\model\\\\net.mat\",\"C:\\\\Program Files (x86)\\\\IMAGE\\\\png\\\\Lab.png\",\"D:\\\\temp\\\\\"]"
Then I pass the string JSON to a *.exe file and deserialize it.
The string the exe received is as follow,which has changed after pass:
string json="[C:\\\\Program Files (x86)\\\\IMAGE\\\\model\\\\net.mat,C:\\\\Program Files
(x86)\\\\IMAGE\\\\png\\\\Lab.png,D:\\\\temp\\]";
Then when I use the follow code to deserialize it,error appear.The code is as follow:
List<string> paths = JsonConvert.DeserializeObject<List<string>>(json);
The error is:
Unhandled JsonReaderException:Unexpected character encountered while parsing value: C. Path '', line 1, position 2.
I wonder why this is the case. Thanks.
You have to put single quotes around the paths.
string json = "[ 'C:\\Program Files (x86)\\IMAGEDL\\model\\net-e-100.mat',C:\\Program Files(x86)\\IMAGEDL\\Labelpng\\Lab.png, D:\\temp\\ ]";

parseLine(String nextLine, boolean multi) in opencsv

I am learning opencsv now,the method parseLine(String nextLine, boolean multi) in CSVParser is a little complex. What is the mearning of the field 'inField' in the class CSVParser? What does 'inQuotes' and 'fromQuotedField' denote in method parseLine(String nextLine, boolean multi); Thanks!
about line 112 in CSVParser : private boolean inField = false ;
about 348 line in parseLine(String nextLine, boolean multi):
boolean inQuotes = false;
boolean fromQuotedField = false;
The inQuotes tells the parser that the data it is reading is inside a quoted string - so if a delemeter character is met then it is part of the string instead of a signal to start a new field.
inField has basically the same functionality but it is a global variable (and it is not dependent on quotations). The reason openCSV needs to know this is that the CSVReader feeds the one line at a time - so if there is a line feed inside one of the fields then it will take multiple calls to the CSVParser to build one complete record. Hence the parseLineMulti.
The fromQuoteFields is a new addition for feature request #60. This is used with the null field indicator to detect if you have a set of empty quotes should the field be an empty string or null.

CSV file (with special characters) upload encoding issue

I am trying to upload a CSV file that has special characters using ServletFileUpload of apache common. But the special characters present in the CSV are being stored as junk characters in the database. The special characters I have are Trademark, registered etc. Following is the code snippet.
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
System.out.println("Form field " + name + " with value "
+ Streams.asString(stream, "UTF-8") + " detected.");
}
}
I have tried reading it using BufferendReader, used request.setCharacterEncoding("UTF-8"), tried upload.setHeaderEncoding("UTF-8") and also checked with IOUtils.copy() method, but none of them worked.
Please advice how to get rid of this issue and where it needs to be addressed? Is there anything I need to do beyond servlet code?
Thanks
What database are using? What character set is database using? Characters can be malformed in the database rather than in Java code.

File.Exist() returns wrong value

I'm am using Asp.net Mvc3!
I wrote following code to search my file into the folder :-
string TrailorsPath =Server.MapPath( "/ePortfolio/"+cid+"/Icons/"+ fileName);
if (System.IO.File.Exists(TrailorsPath))
But it always give incorrect result:
My file path is like that :-
"D:\SVN_HobbyHomes\HobbyHomesWebApp\ePortfolio\1\Icons"
Try to use the "~" at beginning of the path.
string TrailorsPath =Server.MapPath("~/ePortfolio/"+cid+"/Icons/"+ fileName);
there can be multiple problems
put a breakpoint on the line
string TrailorsPath =Server.MapPath( "/ePortfolio/"+cid+"/Icons/"+ fileName);
and check the value of Server.MapPath( "/ePortfolio/"+cid+"/Icons/"+ fileName)
and to begin with use this
Server.MapPath( "~/ePortfolio/"+cid+"/Icons/"+ fileName)

Weird XML exception when sending SOAP request

Have an application which publishes XML data across webservice using SOAP.
The data is pulled directly from an Oracle database and parsed into XML but for some reason the data being pulled out of the DB is throwing the following invalid XML exception.
Have done a bit of research and it looks like it may be a NULL character somewhere in the data which XML parser doesn't like.
Just wondering if anyone had seen this before and if so were they able to fix it at application or database layer?
Thanks!
Here's stack trace...
Exception System.Xml.XmlException: '.', hexadecimal value 0x00, is an invalid character. Line 1, position 79763.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
at System.Xml.XmlTextReaderImpl.ThrowInvalidChar(Int32 pos, Char invChar)
at System.Xml.XmlTextReaderImpl.ParseNumericCharRefInline(Int32 startPos, Boolean expand, BufferBuilder internalSubsetBuilder, Int32& charCount, EntityType& entityType)
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Xml.XmlValidatingReaderImpl.Read()
at System.Xml.XmlValidatingReader.Read()
at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
at System.Xml.XmlDocument.Load(XmlReader reader)
at Microsoft.Web.Services2.Security.MessageSignature.PreProcessElementInput(XmlElement elem)
at Microsoft.Web.Services2.Security.SignatureReference.CalculateHashValue(XmlDocument document, CanonicalXmlNodeList refList)
at Microsoft.Web.Services2.Security.MessageSignature.BuildDigestedReferences()
at Microsoft.Web.Services2.Security.MessageSignature.ComputeKeyedHashSignature(SymmetricKeyAlgorithm key)
at Microsoft.Web.Services2.Security.MessageSignature.ComputeSignature()
at Microsoft.Web.Services2.Security.Security.SerializeXml(SoapEnvelope document)
at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessHeader(Security security, SoapEnvelope envelope)
at Microsoft.Web.Services2.Security.SecurityOutputFilter.ProcessMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.Pipeline.ProcessOutputMessage(SoapEnvelope envelope)
at Microsoft.Web.Services2.OutputStream.Close()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
UPDATE: Here is a selection of data being published.Just plain text basically, this is how it exists in database columns, have included as comma separated.
614494, 2003, 33, 327, 15961, 59652, 2, 2, 3, 2, 1, 10-Dec-08, MY2003 AERO SEDAN, Manual 2.0
What kind of data are you pulling from Oracle? A blog? Image blob?
The reason I ask is Images have headers, which means there will be a null char after the header. Not sure how to escape the null char, however, to make it valid for serialization, but you can possibly do something like base64 encode the image, which will mnean reversing the base64 conversion on the other end.
Outside of that, you should post the exact data you are pulling from Oracle, as that might help with a more specific answer.

Resources