Converting file content to string and store in sharepoint column [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a requirement to allow user to upload any file (pdf, doc, ect) to sharepoint and later on download the file as needed. the upload and download tasks are implemented as asp.net web app. Currently, I convert the file content (byte array) to base64 string and store in sharepoint. For download, I get the content from sharepoint and do convert from base64 to string then I write this string to browser. The result did not look like original file. What is wrong?

From your question it sounds like the problem is you are converting the Base64 data to a string. Since Base64 is a representation of binary data using only printable characters it works fine as a string, but interpreting binary data directly as a string can result in data corruption. It's like trying to edit an EXE file using Notepad.
You need to convert the Base64 back to a byte array and write that to the browser.

Related

Create a File From Binary Data In C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am trying to read a file in binary and create a file of the same format with that binary, this file can be in any commom format like (.docx, .txt, .jpeg, .png ) etc.
I created a text file (test.txt) that has a string This is a text string written in it.
string file = "filelocation"; //this has a file location
byte[] data = File.ReadAllBytes(fileWithExt); // this gives me binary data.....
Now how do i create a file of the same extension with the binary data. ?
Per comment feedback, this is more about encryption than just binary file I/O.
Encryption can be done on a file after it is already saved:
https://learn.microsoft.com/en-us/dotnet/api/system.io.file.encrypt?view=net-5.0
And for basic guidance on working with encryption and files in C#, I'd suggest this Microsoft example walkthrough:
https://learn.microsoft.com/en-us/dotnet/standard/security/walkthrough-creating-a-cryptographic-application
may be this could be helpful
// Specifing a file name
var path = #"file.txt";
// Specifing a new file name
var nPath = #"file2.txt";
// Calling the ReadAllBytes() function
byte[] data = File.ReadAllBytes(path);
// Calling the WriteAllBytes() function
// to write the file contents with the
// specified byte array data
File.WriteAllBytes(nPath, data);

Optimized parse text file, to then upload to Excel [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
My project is to take large amounts of logs, output inside text files and parse some of the data to be made into Excel format.
There is a lot of garbage data in between not needed
This is how one portion of it is like:
2018-05-17 07:16:57.105>>>>>>
{"status":"success", "statusCode":"0", "statusDesc":"Message Processed Sucessfully", "messageNumber":"451", "payload":{"messageCode":"SORTRESPONSE","Id":"5L","Id":"28032","messageTimestamp":"2018-05-16 23:16:55"}}
I will first need to take the time stamp befor the "{}"
as it differs from the messageTimestamp
When generating the excel workbook
This is how it will look like in Excel:
------A-----------------------------------B--------------C
1. Overall time stamp ---------- status------- statusCode
2. 2018-05-17 07:16:57.105 - success --- -0
And so on...
payload has its own section of logs within its "{}"
so its section in excel will look like this:
F
1. payload
2. {"messageCode":"SORTRESPONSE","Id":"5L","Id":"28032","messageTimestamp":"2018-05-16 23:16:55"}
its content can be in one section that's not an issue.
A friend of mine have done something similar but it can take a few minutes to even generate even one relatively small excel document
My Question:
What is the most optimal way can I parse the data needed to then store it in an array or multidimensional array
to then push it into an excel document.
I would try to split the input text on newline characters, then parse the JSON part with Newtonsoft.Json.
I would highly advise to not try to parse the JSON yourself. The bottleneck here will be disk IO not in-memory processing, so make it easy to write correct code and use 3rd party libraries.
Once you have structured data representing the input, you can write each entry to an output file with only the fields you need.
For an Excel file, is CSV okay or do you need XLSX files? For CSV you can just write to a file directly, for XLSX I would recommend the EPPlus library.
https://www.newtonsoft.com/json
https://archive.codeplex.com/?p=epplus

How I can read after EOF? C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I`m using C# and I need to read something after EOF. Is it possible by using C#? How?
Thanks.
You cant. EOF means end of file, there's nothing actually in the file after that.
You may as well ask how you can get ten gallons of oil from a four-gallon drum. Once it's empty, there's no more to be had.
Since you're talking C# hence Windows (and based on your comment and data located behind the end of file pointer), it's possible that they may be referring to "DOS mode" text files, which are (or used to be, I haven't investigated recently) terminated by the CTRL-Z character.
From the earliest days of the PC revolution, where CP/M used integral numbers of disk blocks to store a file and only stored the number of disk blocks rather than the number of bytes, CTRL-Z was used to indicate end of file if the file wasn't an exact multiple of the disk block size.
If that's the case, it's probably best just to open the file as a binary file, then read up to the first CTRL-Z character (code point 26) - everything beyond that could be considered data beyond EOF if it's truly a text file of that format.

have to extract data from a word file [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a peculiar problem in that I have to extract information from a word file. Say for example I have a resume and need to extract name, email address, phone no., address, university,Experience etc.
Every other person may be having their resume in a different format.So is there any way by which I can programmatically extract the information I need?
I need this information to fill-up a form for registration.
Even if at first you might be attracted by the idea of using Com Interop and Asp.net, don't do it.
http://support.microsoft.com/kb/257757
That said, it's important to know which version of word are we talking about. Newer formats allow treat them as a zip containing xml files and there are good&free libraries.
http://docx.codeplex.com/
Convert the word document to html, with aspose .net.
Then you can use regular expressions to search the word and/or pdf documents.
Or you can use HTMLAgilityPack to parse the created HTML documents, and search for specific sections/paths.
PS:
If you have a regex for email that's shorter than one page, then the regex is incorrect.
Phone should be manageable, as long as you have to support only one country.
As for name and address, good luck with that.
Edit:
Like this
VB.NET:
Dim doc As New Aspose.Words.Document("filename.docORdocx")
doc.Save("filename.html", Aspose.Words.SaveFormat.Html)
C#:
Aspose.Words.Document doc = new Aspose.Words.Document("filename.docORdocx");
doc.Save("filename.html", Aspose.Words.SaveFormat.Html);
The component is here:
http://www.aspose.com/.net/word-component.aspx
To find out what a valid email address is, read RFC 822:
http://www.faqs.org/rfcs/rfc822.html

how to convert or display emf image in c#? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
this is a part of the documentation for a device I'm working on.
any idea how to interpret this to an image or bitmap or anything usable?
this definition below is xml definitions
3.2.13. IMAGE
properties: content complex
children: IMAGE_DATA
used by: complexType Cbc_Result
attributes: Name Type Use Default Fixed Annotation
ImageType Type_Image required
DataSize xs:long required
This node gathers information on an images files calculated by the software(Image_Data represents entire content of an emf file representing an image)
sample data :
< IMAGE DataSize="6676" ImageType="3">< IMAGE_DATA>AQAAAGwAAAAAAAAAAAAAAMcAAABjAAAAA
AAAAAAAAABNEgAANQwAACBFTUYAAAEAFBoAAI0AAAAF
AAAAAAAAAAAAAAAAAAAAVgUAAAADAABAAQAA8AAAAAAAAAAAAAAAAAAAAADiBACAqQMAEQAAAAwA
AAAIAAAAEgAAAAwAAAACAAAAFAAAAAwAAAANAAAACQAAABAAAADIMgAAjBwAAAkAAAAQAAAAyDIA
AIwcAAALAAAAEAAAAMgAAABkAAAASwAAAEAAAAAwAAAABQAAACAAAAABAAAAAQAAABAAAAAAAAAA
AAAAADB1AAAwdQAAAA< /IMAGE_DATA>< /IMAGE>
Looks like Base64 encoded (with stripped == signes at the end) content of file in EMF format - http://en.wikipedia.org/wiki/Windows_Metafile.
Make sure to add needed number of = at the end (http://en.wikipedia.org/wiki/Base64 for details) to successfully use Conver.FromBase64 function to get byte array.
I don't know if regular rendering methods support EMF... But Check Drawing namespace and Image class in particular.

Categories