I am storing some xml in XMLReader as under (read from url). There there any way I can save this to disk?
Stream^ xml= getDataStream( gcnew System::String( m_contentUrl.c_str() ) );
XmlReader^ xmlTextReader = nullptr;
xmlTextReader = XmlTextReader::Create( xml );
Thanks
Related
The Apache Commons compress library seems focused around writing a TarArchiveEntry to TarArchiveOutputStream. But it looks like the only way to create a TarArchiveEntry is with a File object.
I don't have files to write to the Tar, I have byte[]s in memory or preferably streams. And I don't want to write a bunch of temp files to disk just so that I can build a tar.
Is there any way I can do something like:
TarEntry entry = new TarEntry(int size, String filename);
entry.write(byte[] fileContents);
TarArchiveOutputStream tarOut = new TarArchiveOutputStream();
tarOut.write(entry);
tarOut.flush();
tarOut.close();
Or, even better....
InputStream nioTarContentsInputStream = .....
TarEntry entry = new TarEntry(int size, String filename);
entry.write(nioTarContentsInputStream);
TarArchiveOutputStream tarOut = new TarArchiveOutputStream();
tarOut.write(entry);
tarOut.flush();
tarOut.close();
Use the following code:
byte[] test1Content = new byte[] { /* Some data */ };
TarArchiveEntry entry1 = new TarArchiveEntry("test1.txt");
entry1.setSize(test1Content.length);
TarArchiveOutputStream out = new TarArchiveOutputStream(new FileOutputStream("out.tar"));
out.putArchiveEntry(entry1);
out.write(test1Content);
out.closeArchiveEntry();
out.close();
This builds the desired tar file with a single file in it, with the contents from the byte[].
i use My.Computer.Network.UploadFile method for file upload to FTP .
But i have some problem . My problem is Upload Speed .
Ex: i use some FTP program (FileZilla) and my upload speed 4 Mb/sn.
but My.Computer.Network.UploadFile method is 1.20Mb/sn limit .
Why this method is limited ? Can i up Upload speed ?
Use this code pal and inform me if this will be useful:
using System.Net;
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://
XXXXXXXXXXXXXXXXXXXXX/" + "C:/XXXXX.zip");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("User", "PassWord");
// Copy the contents of the file to the request stream.
Stream ftpStream = request.GetRequestStream();
FileStream file = File.OpenRead("C:/XXXXX.zip");
int length = 1024;
byte[] buffer = new byte[length];
int bytesread = 0;
do
{
bytesread = file.Read(buffer,0,length);
ftpStream.Write(buffer,0,bytesread);
}
while(bytesread != 0);
file.Close();
ftpStream.Close();
MessageBox.Show("Uploaded Successfully");
I am a bit confused on how to do this, all of the docs / examples show how to read and edit xml docs but there doesn't seem to be any clear way of creating an xml from scratch, I would rather not have to ship my program with a dummy xml file in order to edit one. any ideas? thanks.
What you could do instead would be to just hard-code an empty document like this:
byte[] emptyDoc = "<?xml version='1.0' encoding='UTF-8'?><root></root>".getBytes("UTF-8");
And then use that to create your VTDGen and XMLModifier, and start adding elements:
VTDGen vg = new VTDGen();
vg.setDoc(emptyDoc);
vg.parse(true);
VTDNav vn = vg.getNav();
XMLModifier xm = new XMLModifier(vn);
// Cursor is at root, update Root Element Name
xm.updateElementName("employee");
xm.insertAttribute(" id='6'");
xm.insertAfterHead("<name>Bob Smith</name>");
vn = xm.outputAndReparse();
// etc...
I'm trying to write a simple hello world application in C++/CLI to create a Word document which I've posted below
int main(array<String^>^ args)
{
String^ documentFileName=L"Hello4.docx";
WordprocessingDocument ^myDoc = WordprocessingDocument::Create(documentFileName, WordprocessingDocumentType::MacroEnabledDocument);
MainDocumentPart^ mainPart = myDoc->AddMainDocumentPart();
mainPart->Document = gcnew Document();
Body^ body = gcnew Body();
Paragraph^ paragraph = gcnew Paragraph();
Run^ run_paragraph = gcnew Run();
DocumentFormat::OpenXml::Wordprocessing::Text^ text_paragraph = gcnew DocumentFormat::OpenXml::Wordprocessing::Text(L"Hello ..asdks");
run_paragraph->Append(text_paragraph);
paragraph->Append(run_paragraph);
body->Append(paragraph);
mainPart->Document->Append(body);
mainPart->Document->Save();
return 0;
}
The above program creates hello.docx file but I'm not able to open the created file as it is corrupt.Can you please help me with this
Thanks in advance
Try using a local variable instead of reading back from the property. e.g.
doc = gcnew Document();
mainPart->Document = doc;
//...
doc->Append(body);
doc->Save();
I have a .resx file to update some data. I can read the data from the file via a ResXResourceSet object, but when I want to save the data back, the saved data format is
unrecognizable. How do I edit .resx files? Thanks.
ResXResourceSet st = new ResXResourceSet(#"thepath");
entries=new List<DictionaryEntry>();
DictionaryEntry curEntry ;
foreach (DictionaryEntry ent in st)
{
if (ent.Key.ToString() == "Page.Title")
{
curEntry = ent;
curEntry.Value = "change this one"
entries.Add(curEntry);
}
else
{
entries.Add(ent);
}
}
st.Close();
System.Resources.ResourceWriter wr = new ResourceWriter(#"thepath");
foreach (DictionaryEntry entry in entries)
{
wr.AddResource(entry.Key.ToString(), entry.Value.ToString());
}
wr.Close();
Hi again i searched up and found that..
ResourceWriter writes data as binary type
ResourceReader reads data as binary type
ResXResourceWriter writes data as xml format
ResXResourceReader reads data as xml format
so example on top using ResXResourceWriter,ResXResourceReader instead of ResourceReader ,ResourceWriter will manipulate resources as xml type