Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[.NET] File properties aanpassen

Pagina: 1
Acties:

  • Montaner
  • Registratie: Januari 2005
  • Laatst online: 14-11 10:35
Voor het verwerken van bepaalde bestanden is het voor mij nodig om een title aan te passen van een bestand mocht dat te lang zijn. Het gaat hierbij om foto's (geen idee of dat relevant is). Röntgen apparaten en andere abnormale foto toestellen willen hierin nog wel eens overbodige waardes plaatjes, zoals een volledige XML.

Nu had ik eigenlijk wel verwacht dat er in .NET een manier was om de eigenschappen van een bestand aan te passen, zonder zelf in de hexadecimalen te gaan klooien. Sinds het in Windows al zo simpel is, rechtermuisknop --> eigenschappen --> details --> titel. Maar voor zover heb ik er vrij weinig over kunnen vinden.

File.SetAttributes heeft enkel toegang tot de kenmerken van een bestand, niet de details. http://msdn.microsoft.com...attributes(v=vs.110).aspx

Ik heb al een hele tijd lopen zoeken op Google, maar een library of class kom ik ook niet tegen.

Mijn probleemstelling is eigenlijk heel eenvoudig;
Is een titel langer dan 30 karakters, verwijderen en opslaan.

  • Viper®
  • Registratie: Februari 2001
  • Niet online
Kijk eens naar deze:
http://www.codeproject.co...led-information-of-a-File

Of anders deze:
- You need to download the "Microsoft Developer Support OLE File Property Reader 2.1 Sample" from
http://www.microsoft.com/...EC8300C4C2&displaylang=en
- Create a new C# VS.NET project (I used a windows application in this case).
- Add a reference to C:\DsoFile\dsofile.dll to you project (this was the default location).
- Add a button to the form.
- Add the following code to the button:


Code Block
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void button1_Click(object sender, EventArgs e)
{
  //This is the PDF file we want to update.
  string filename = @"c:\temp\MyFile.pdf";
  //Create the OleDocumentProperties object.
  DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
  //Open the file for writing if we can. If not we will get an exception.
  dso.Open(filename, false,
 
    DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
  //Set the summary properties that you want.
  dso.SummaryProperties.Title = "This is the Title";
  dso.SummaryProperties.Subject = "This is the Subject";
  dso.SummaryProperties.Company = "RTDev";
  dso.SummaryProperties.Author = "Ron T.";
  //Save the Summary information.
  dso.Save();
  //Close the file.
  dso.Close(false);
}


bron: MSDN: Setting file info/attributes (author, subject, ..)

  • Acid_Burn
  • Registratie: Augustus 2001
  • Laatst online: 02:58

Acid_Burn

uhuh

Bij foto's denk ik eigenlijk aan EXIF data. Dus misschien heb je hier wat aan: http://www.codeproject.co...43665/ExifLibrary-for-NET

Glass Eye Photography | Zelfbouw wireless fightstick | Mijn puzzel site


  • Montaner
  • Registratie: Januari 2005
  • Laatst online: 14-11 10:35
Viper® schreef op maandag 28 juli 2014 @ 11:02:
Kijk eens naar deze:
http://www.codeproject.co...led-information-of-a-File

Of anders deze:
- You need to download the "Microsoft Developer Support OLE File Property Reader 2.1 Sample" from
http://www.microsoft.com/...EC8300C4C2&displaylang=en
- Create a new C# VS.NET project (I used a windows application in this case).
- Add a reference to C:\DsoFile\dsofile.dll to you project (this was the default location).
- Add a button to the form.
- Add the following code to the button:


Code Block
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
private void button1_Click(object sender, EventArgs e)
{
  //This is the PDF file we want to update.
  string filename = @"c:\temp\MyFile.pdf";
  //Create the OleDocumentProperties object.
  DSOFile.OleDocumentProperties dso = new DSOFile.OleDocumentProperties();
  //Open the file for writing if we can. If not we will get an exception.
  dso.Open(filename, false,
 
    DSOFile.dsoFileOpenOptions.dsoOptionOpenReadOnlyIfNoWriteAccess);
  //Set the summary properties that you want.
  dso.SummaryProperties.Title = "This is the Title";
  dso.SummaryProperties.Subject = "This is the Subject";
  dso.SummaryProperties.Company = "RTDev";
  dso.SummaryProperties.Author = "Ron T.";
  //Save the Summary information.
  dso.Save();
  //Close the file.
  dso.Close(false);
}


bron: MSDN: Setting file info/attributes (author, subject, ..)
Met de eerste kan je enkel lezen. De 2e lijkt enkel voor Office documenten te zijn, alhoewel in de example wel een PDF document wordt gebruikt.

Ik gebruik in mijn geval een TIF bestand, en krijg daarmee deze error:
Naam is niet geldig. (Exception from HRESULT: 0x800300FC (STG_E_INVALIDNAME))

Ik krijg de error overigens enkel in VB.NET, in C# runt de code wel, maar past niets aan.

Een Word document gaat wel prima.

@AcidBurn,

Het is helaas geen EXIF informatie. Dat zou het wel moeten zijn eigenlijk........ eigenwijze programmeurs of zo ;-).

[ Voor 5% gewijzigd door Montaner op 28-07-2014 12:04 ]


  • Tribits
  • Registratie: Augustus 2011
  • Laatst online: 02:56

Tribits

Onkruid vergaat niet

Volgens mij heb je iets nodig dat om kan gaan met de specifieke metadata van je tiff bestanden. Mogelijk werkt de methode die in dit artikel wordt uitgelegd:

MSDN: Reading and Writing Metadata (Windows)
trix0r schreef op maandag 28 juli 2014 @ 11:55:
[...]

Het is helaas geen EXIF informatie. Dat zou het wel moeten zijn eigenlijk........ eigenwijze programmeurs of zo ;-).
TIFF is een jaar of 10 ouder dan Exif, ik kan me er wel iets bij indenken dat sommige applicaties nog aan oude standaarden vasthouden.

[ Voor 38% gewijzigd door Tribits op 28-07-2014 16:00 ]

Master of questionable victories and sheer glorious defeats


  • Montaner
  • Registratie: Januari 2005
  • Laatst online: 14-11 10:35
Ok.. het is me gelukt met de volgende library:
http://bitmiracle.com/libtiff/

De title/subject is tag 0x010e oftewel 270 (Image Description).

Iedereen dank voor de moeite.
Pagina: 1