1

Before you read on there is similar question asked by me at How to remove special characters from file Metadata c#. This question is not specific to any File type(image, video, audio, text, word, excel.). I am not asking how to get file's extended properties and how to set them.

Is it possible to copy file contents from one file to another without copying file's extended properties.

Please check following image for what I mean to say by extended properties.

enter image description here

Note: Ignore highlighting. It doesn't mean anything here.

I want the file contents but I don't want to get Title, Subject, Rating, Tags, Comments, Authors etc. (None of the properties, irrespective of the file type.).

Thanks.

Community
  • 1
  • 1
Nikhil Chavan
  • 1,685
  • 2
  • 20
  • 34
  • those could be embbeded in the image themselves. have you tried a byte for byte copy? – Daniel A. White Jul 14 '15 at 12:50
  • It depends on the type of the file. Some files hold that extra data inside the file itself and others use a alternate file stream to hold the data. There is no generic solution for files that hold the extra info inside the file. – Scott Chamberlain Jul 14 '15 at 12:50
  • @DStanley I do not agree with you that the other post is a duplicate, this question is asking specifically about clearing file metadata not how to copy a file in the first place. If you copy a MP3 file using the methods explained in the duplicate you still will have all of the ID3 extended information show up. – Scott Chamberlain Jul 14 '15 at 12:53
  • @ScottChamberlain Fair enough. – D Stanley Jul 14 '15 at 12:55
  • possible duplicate of [How to remove special characters from file Metadata c#](http://stackoverflow.com/questions/31402506/how-to-remove-special-characters-from-file-metadata-c-sharp) – David Arno Jul 14 '15 at 12:58
  • @D Stanley - I know how to copy file contents from one file to another. Still I respect your decision. But could you please point to any answer in that question that describes about not copying file metadata? – Nikhil Chavan Jul 14 '15 at 12:58
  • You have already asked this question and accepted an answer. Why are you asking it again? – David Arno Jul 14 '15 at 12:58
  • The comments are part of the file contents. As explained in your other question, you need to load the image from file into memory, modify the metadata (such as removing the comment) and then save the image once more. – David Arno Jul 14 '15 at 13:00
  • @DavidArno - The answer I got there was correct for image files only, You can read answer if you want. Also this question is not about getting File's extended properties but to remove them when copying to another file. – Nikhil Chavan Jul 14 '15 at 13:01
  • @NikhilChavan, of course it only covers images as you are asking how to modify image properties. What other properties are you trying to change? – David Arno Jul 14 '15 at 13:06
  • @DavidArno - Sorry David, but I had asked for 'File' and for 'Image', you can read question again. It might be confusing because I have posted image of 'JPG' file properties. But my intent was to display what properties I want modify. – Nikhil Chavan Jul 14 '15 at 13:13

1 Answers1

2

You'll probably find it easier modifying the extended properties after the file has copied. Take a look at the File class, it has methods for setting the modified date, etc.

For Title etc. you will have to use COM, shell32.dll will allow you to do this:

http://www.codeproject.com/cs/files/detailedfileinfo.asp

To alter these properties you will have to use another COM component. It looks like dsofile.dll will do this for you. There is an MS KB article on it here

You might also take a look at TagLib# although I don't know if it has the ability to work generically.

NibblyPig
  • 51,118
  • 72
  • 200
  • 356
  • I have used Shell32.dll, COM to get files extended properties. It is working perfectly, but there is no way to write back properties to file or to modify them. Correct me if I am wrong. – Nikhil Chavan Jul 14 '15 at 13:03
  • I already checked using dsofile.dll, but it doesn't work for all file types (Not for even .docx files). TagLib does provide commonly used file formats but does not cover all types. – Nikhil Chavan Jul 14 '15 at 13:16
  • the dosfile.dll was last modified on 05-01-2007 15:22. It is more than 6 years old now. There should be some new approach and that's what I am trying to find. – Nikhil Chavan Jul 14 '15 at 13:20
  • MetaData has existed since at least Windows XP in 2001, so to preserve compatibility I wouldn't expect any new approaches to exist. It appears it is an NTFS feature according to this article: https://filemeta.codeplex.com/ which might offer further insight. Source code is available which may help you. – NibblyPig Jul 14 '15 at 13:39
  • Thanks for the solutions, it was great to to discuss with you. I finally ended up with using TagLib# for media files. – Nikhil Chavan Jul 15 '15 at 05:09