WMF to Base64String

capri

Active member
Joined
Jun 16, 2015
Messages
42
Programming Experience
5-10
Hi,

Is it possible to convert a wmf file to Base64String?

Thanks
 
A base-64 string is a text representation of binary data, so it's possible to convert any binary data to base-64. If you want the binary contents of a file as a base-64 string then try this:
var base64Text = Convert.ToBase64String(System.IO.File.ReadAllBytes(filePathHere));
You can pass any byte array to be converted and you can get a byte from any file with File.ReadAllBytes. This is information you could have found fairly easily if you'd looked doe general information on files and converting data instead of assuming that there is something specific to this type of file.
 
:confused: I tried many ways but didn't know it's this easy. How do I get the metafile back from the base64String?
 
How do I get the metafile back from the base64String?

I can only assume that you have put exactly zero effort into answering that question for yourself. What does my code actually do? It reads a file into a byte array and then converts that byte array to a base-64 string. Is it not logical that the process to achieve the reverse would be to convert a base-64 string to a byte array and then write that byte array to a file? That's just simple logic, not programming. If the Convert.ToBase64String method converts a byte array to a base-64 string then can you not make any intuitive leap as to where you might find a method that converts a base-64 string to a byte array? Similarly, if the File.ReadAllBytes method reads a file into a byte array, have you no clue as to how you might write a byte array to a file?

I'm not trying to be mean when I say that if small steps of logic like this are a challenge then programming will not be a pleasure for you. In my experience, it's usually the case that people are held back more often by a willingness to actually try to make these logical steps rather than their actual ability to do so, i.e. I think you can do it if you make the effort. If you haven't used the Help menu in VS for a start then you haven't really tried. For instance, you already know about the Convert class and the File class because I've already told you about them. If you haven't used the Help menu to open the documentation for those classes to see what other members they have, e.g. methods that might perform the reverse operations here, then you really haven't tried. I say this for your benefit, not mine, because you're the one who will improve their ability to answer their own questions by doing so. I know from personal experience.
 
That is also my question.please help us.

I already have helped. If you aren't prepared to make the effort to use that help then that's on you. A moment's thought should be all you need. Here's a hint. If you use Convert.ToBase64String to convert data to a base-64 String, what do you think you use to convert data from a base-64 String? See how easy it is?
 
Back
Top Bottom