473,396 Members | 1,996 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,396 software developers and data experts.

How programmatically set file attribute to not be read-only?

From within my project, I am opening an file elsewhere on the network and
changing contents within.

When I go to close/save, however, I can't because it's read-only (as it's
checked in).

Can I just flip read-only off, make my changes and save it, and then flip
read only back on (programmatically)? How can I do this, please?

Thanks.

Sep 16 '08 #1
1 4269
rcook349 kirjoitti:
From within my project, I am opening an file elsewhere on the network
and changing contents within.

When I go to close/save, however, I can't because it's read-only (as
it's checked in).

Can I just flip read-only off, make my changes and save it, and then
flip read only back on (programmatically)? How can I do this, please?

Thanks.
using System.IO;

if (File.Exists(fileName))
{
FileAttributes attrs = File.GetAttributes(fileName);
File.SetAttributes(fileName, attrs & ~FileAttributes.ReadOnly);
MakeTheChanges(fileName);
attrs = File.GetAttributes(fileName);
File.SetAttributes(fileName, attrs | FileAttributes.ReadOnly);
}

There is two calls to GetAttributes, since most likely your
MakeTheChanges sets at least the archive bit.

--
Arto Viitanen

Sep 16 '08 #2

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

Similar topics

2
by: Jak Sparrow | last post by:
What are some good ways to programmatically check for software already installed on a computer? For example, to check a version of Internet Explorer, a program can check the registry for the...
13
by: Alexandra | last post by:
Hi, I have a hidden system file that I need to read. I am logged in as an administrator. I can not change the file attributes using the windows explorer.
4
by: | last post by:
I have a "form field highlight" javascript that I've added to some of my ASP.NET forms using the following syntax: body.Attributes.Add("onClick", "highlight(event);");...
2
by: Reza Solouki | last post by:
Hello, I never had to do anything with office tools programmatically till now(I guess there is first time for everything), so this might be a very silly and simple question for some of you. Any...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
0
by: Nathan Sokalski | last post by:
I need to programmatically set the action attribute of the form tag. First of all, the ASP.NET form control does not have an action property (it shows the Action attribute in source view, but not...
7
by: Tim Zych | last post by:
I would like a way to scan the code in a vb.net project, say by creating a vb.net utility to cycle through each line of code related to a particular project and perform some analysis on it. How...
6
by: Brian Roisentul | last post by:
Hi everyone, I've been investigating for a while about this, but with no luck yet. Does anybody know a way to do it? Many thanks, Brian
11
by: =?Utf-8?B?UGV0ZXIgSw==?= | last post by:
I am working with Visual Studio or alternately with Expression Web. I need to create about 50 aspx pages with about 1200 thumbnali images, typically arranged in three to four groups per page,...
6
by: Andrew Jocelyn | last post by:
Hi How do I programmatically change (read/write) the values in this app.config file at runtime? Specifically I want to change the client endpoint address but it would be nice to change other...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.