Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.
Thu May 31, 2018 2:31 pm
Hello,
I am trying to loop through all files in a specific directory and to make sure there is a watermark present. What would be the best way to go about doing this. I am looping through the files using a foreach loop but I am confused about how to actually check multiple files using the watermarktype class, while looping through.
string[] filePaths = Directory.GetFiles(@"C: \Users\athomp365\desktop\ccdocs","*.docx",
SearchOption.AllDirectories);
foreach (string fileOne in filePaths)
{
MessageBox.Show(fileOne);
}
-
athomp365
-
- Posts: 6
- Joined: Thu May 24, 2018 12:37 pm
Fri Jun 01, 2018 6:06 am
Hello athomp365,
Thank you for your post.
Below is the code for your kind reference.
- Code: Select all
private void button1_Click(object sender, EventArgs e)
{
string[] filePaths = Directory.GetFiles(@"C: \Users\athomp365\desktop\ccdocs", "*.docx", SearchOption.AllDirectories);
foreach (string fileOne in filePaths)
{
IfHasWatermark(fileOne);
}
}
private static bool IfHasWatermark(string fileName)
{
Document doc = new Document();
doc.LoadFromFile(fileName);
WatermarkType type = doc.Watermark.Type;
if (type == WatermarkType.NoWatermark)
{
MessageBox.Show(fileName + "has no watermark");
return false;
}
else
{
MessageBox.Show(fileName + "has a" + type.ToString());
return true;
}
}
Sincerely,
Jane
E-iceblue support team
-
Jane.Bai
-
- Posts: 1156
- Joined: Tue Nov 29, 2016 1:47 am
Fri Jun 01, 2018 12:59 pm
Your awesome, thank you so much Jane.
-
athomp365
-
- Posts: 6
- Joined: Thu May 24, 2018 12:37 pm
Mon Jun 04, 2018 1:35 am
Hello athomp365,
Thank you for your valuable feedback.
Do not hesitate to contact us if you need any help.
Sincerely,
Jane
E-iceblue support team
-
Jane.Bai
-
- Posts: 1156
- Joined: Tue Nov 29, 2016 1:47 am