472,353 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

File's custom attributes

How can i read/write file's custom attributs(like subject,author...) in
C#???

Thanks :))
Nov 15 '05 #1
3 26050
Gets the FileAttributes of the file on the path.

[Visual Basic]
Public Shared Function GetAttributes( _
ByVal path As String _
) As FileAttributes
[C#]
public static FileAttributes GetAttributes(
string path
);
[C++]
public: static FileAttributes GetAttributes(
String* path
);
[JScript]
public static function GetAttributes(
path : String
) : FileAttributes;
Parameters
path
The path to the file.
Return Value
The FileAttributes of the file on the path, or -1 if the path or file is not
found.

Exceptions
Exception Type Condition
ArgumentException path is empty, contains only white spaces, or
contains invalid characters.
PathTooLongException The specified path, file name, or both exceed the
system-defined maximum length. For example, on Windows-based platforms,
paths must be less than 248 characters, and file names must be less than 260
characters.
NotSupportedException path is in an invalid format.
DirectoryNotFoundException The specified path is invalid, such as
being on an unmapped drive.

Remarks
The path parameter is permitted to specify relative or absolute path
information. Relative path information is interpreted as relative to the
current working directory. To obtain the current working directory, see
GetCurrentDirectory.

For an example of using this method, see the Example section below. The
following table lists examples of other typical or related I/O tasks.

To do this... See the example in this topic...
Create a text file. Writing Text to a File
Write to a text file. Writing Text to a File
Read from a text file. Reading Text from a File
Append text to a file. Opening and Appending to a Log File
File.AppendText

FileInfo.AppendText

Rename or move a file. File.Move
FileInfo.MoveTo

Read from a binary file. Reading and Writing to a Newly Created Data
File
Write to a binary file. Reading and Writing to a Newly Created Data
File
Set file attributes. SetAttributes

Example
[Visual Basic, C#, C++] The following example demonstrates the GetAttributes
and SetAttributes methods by applying the Archive and Hidden attributes to a
file.

[Visual Basic]
Imports System
Imports System.IO
Imports System.Text

Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\temp\MyTest.txt"
' Delete the file if it exists.
If File.Exists(path) = False Then
File.Create(path)
End If

If (File.GetAttributes(path) And FileAttributes.Hidden) =
FileAttributes.Hidden Then
' Show the file.
File.SetAttributes(path, FileAttributes.Archive)
Console.WriteLine("The {0} file is no longer hidden.", path)
Else
' Hide the file.
File.SetAttributes(path, File.GetAttributes(path) Or
FileAttributes.Hidden)
Console.WriteLine("The {0} file is now hidden.", path)
End If
End Sub
End Class
[C#]
using System;
using System.IO;
using System.Text;

class Test
{
public static void Main()
{
string path = @"c:\temp\MyTest.txt";
// Delete the file if it exists.
if (!File.Exists(path))
{
File.Create(path);
}

if ((File.GetAttributes(path) & FileAttributes.Hidden) ==
FileAttributes.Hidden)
{
// Show the file.
File.SetAttributes(path, FileAttributes.Archive);
Console.WriteLine("The {0} file is no longer hidden.", path);
}
else
{
// Hide the file.
File.SetAttributes(path, File.GetAttributes(path) |
FileAttributes.Hidden);
Console.WriteLine("The {0} file is now hidden.", path);
}
}
}
[C++]
#using <mscorlib.dll>

using namespace System;
using namespace System::IO;
using namespace System::Text;

void main() {
String* path = S"c:\\temp\\MyTest.txt";
// Delete the file if it exists.
if (!File::Exists(path)) {
File::Create(path);
}

if ((File::GetAttributes(path) & FileAttributes::Hidden) ==
FileAttributes::Hidden) {
// Show the file.
File::SetAttributes(path, FileAttributes::Archive);
Console::WriteLine(S"The {0} file is no longer hidden.", path);
} else {
// Hide the file.
File::SetAttributes(path,
static_cast<FileAttributes>(File::GetAttributes(pa th) |
FileAttributes::Hidden));
Console::WriteLine(S"The {0} file is now hidden.", path);
}
}
--

Duncan McNutt
Microsoft Product Deactivation Team
--
"StGo" <go******@ness-isi.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
How can i read/write file's custom attributs(like subject,author...) in
C#???

Thanks :))

Nov 15 '05 #2
Hi, StGo:
If you mean the summary(auther, title, subject) properties of files
on NTFS or ole ducments, you may want to check out Dsofile activx control
provided by Microsoft. You need to download it from the following link and
import it into your project.

http://support.microsoft.com/default...NoWebContent=1

Hope it helps
Qiu

"StGo" <go******@ness-isi.com> wrote in message
news:eQ**************@TK2MSFTNGP09.phx.gbl...
How can i read/write file's custom attributs(like subject,author...) in
C#???

Thanks :))

Nov 15 '05 #3


Sank's for answer!

But I'm mean to non standart attributs like subject,comments and
possibility adding custom attributs
like "custom_version=1.6".

If you can,please help me:)
Thanks

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Bret Pehrson | last post by:
I've converted a non-trivial C++ library to managed, and get the following unhelpful linker error: Assignment.obj : error LNK2022: metadata...
1
by: Tamas Demjen | last post by:
I started to experiment with VC++ 2005 Beta1. So far everything went fine, and already have a working project, but soon I realized that the...
3
by: Edward Grosso via .NET 247 | last post by:
Hi to all the dotnet community, I'm actually trying to figure out how can I save a Recordset to an ASCII file with custom field separators, in a...
3
by: tshad | last post by:
Is there a way to use a custom button with the: <Input ID="MyFile" Type="File" RunAt="Server">? This gives you a generic button, but I would...
7
by: Julian Jelfs | last post by:
Hi, I had an aspx pag in .Net 1.1 with a label on it. As such I had a code behind page with a declaration for that label. When I convert to...
3
by: serge calderara | last post by:
Dear all, Let say that I have developped a funcionnal library that I distribute for use. That library can be integrated in a project by...
1
by: steve | last post by:
Hi all, Here's some work in progress that should allow you to run a batch file as a custom action in a VS deployment project. Yup I know you can...
1
by: Ryan | last post by:
I am trying to log events to SQL Server instead of the computers event log, but, although I get no errors, I have no luck. The webevents_events...
2
by: P4trykx | last post by:
Hello I'm want to add some custom attributes to WebControls using WebControl.Attributes.Add("abc","234"); So the html output will look like this,...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.