473,416 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 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 26225
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 operation failed (80131195) : Custom attributes are...
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 compiler was ancient (not supporting half of the C++/CLI...
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 fast way, without loops. Perhaps there is some way...
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 like to use my own button that has the same style...
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 Asp.Net 2.0 the code behind is converted to a...
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 referencing it and then use it by calling function and...
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 use js or wsh, but the target may not have...
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 table is empty. I have a custom event that I am...
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, <input type="hidden" abc="123" /etc. I know...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.