Reputation: 435
I'm wondering how I can create my own file extension to work with my application. For example, say I wanted to have a ".abc" extension. The full file name example would be "MyFile.abc".
I want the file to behave in a way that when it is double clicked, it will open up in my application, but actually it contains data of a .xml file.
Sorry if this makes little sense, this is completely new to me. I'm using c# in visual studio 2013, and basically my application is an automatic update installer. I want it so when my file with my own extension is selected, my application opens and uses the xml data from it to do the update.
Upvotes: 4
Views: 12358
Reputation: 1
using System;
namespace LibraryCatalog
{
// Author class to represent an author of books
public class Author
{
// Properties
public string Name { get; private set; }
public DateTime Birthdate { get; private set; }
// Constructor to initialize properties
public Author(string name, DateTime birthdate)
{
Name = name;
Birthdate = birthdate;
}
}
// Book class to represent a book in the library
public class Book
{
// Properties
public string Title { get; private set; }
public string ISBN { get; private set; }
public Author Author { get; private set; }
public bool Availability { get; private set; }
// Constructor to initialize properties
public Book(string title, string isbn, Author author)
{
Title = title;
ISBN = isbn;
Author = author;
Availability = true; // By default, a new book is available
}
// Method to check out the book
public bool CheckOut()
{
if (Availability)
{
Availability = false; // Set availability to false when checked out
Console.WriteLine($"The book '{Title}' has been checked out.");
return true; // Successful checkout
}
else
{
Console.WriteLine($"The book '{Title}' is currently not available.");
return false; // Unsuccessful checkout
}
}
// Method to return the book
public void Return()
{
Availability = true; // Set availability to true when returned
Console.WriteLine($"The book '{Title}' has been returned.");
}
}
// Example usage
class Program
{
static void Main(string[] args)
{
// Create an author
Author author = new Author("George Orwell", new DateTime(1903, 6, 25));
// Create a book
Book book = new Book("1984", "1234567890", author);
// Check out the book
book.CheckOut();
// Try to check out the book again
book.CheckOut();
// Return the book
book.Return();
// Check out the book again
book.CheckOut();
}
}
}
Upvotes: 0
Reputation: 2151
You can create your own files with custom extensions by saving the file with that particular extension. Then what you need is to associate the extension with your application. For this you need to create the instance of FileAssociationInfo .
Check this out System-File-Association
Upvotes: 4