TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to create Library management in windows application
Muthuramalingam Duraipandi
Aug 09
2016
Code
2.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
libraryman.ZIP
// Mainpage1.cs
using
System;
using
System.Collections.Generic;
using
Windows.UI.Xaml.Controls;
namespace
SDKTemplate
{
public
partial
class
MainPage : Page
{
public
const
string
FEATURE_NAME =
"Library management C# sample"
;
List<Scenario> scenarios =
new
List<Scenario>
{
new
Scenario() { Title =
"Adding a folder to the Pictures library"
, ClassType =
typeof
(Scenario1) },
new
Scenario() { Title =
"Listing folders in the Pictures library"
, ClassType =
typeof
(Scenario2) },
new
Scenario() { Title =
"Removing a folder from the Pictures library"
, ClassType =
typeof
(Scenario3) }
};
}
public
class
Scenario
{
public
string
Title {
get
;
set
; }
public
Type ClassType {
get
;
set
; }
}
}
//addfolder.cs
using
System;
using
Windows.Storage;
using
Windows.UI.Xaml;
using
Windows.UI.Xaml.Controls;
using
Windows.UI.Xaml.Navigation;
namespace
SDKTemplate
{
public
sealed
partial
class
Scenario1 : Page
{
public
Scenario1()
{
this
.InitializeComponent();
}
protected
override
void
OnNavigatedTo(NavigationEventArgs e)
{
}
private
async
void
AddFolderButton_Click(
object
sender, RoutedEventArgs e)
{
StorageLibrary picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
StorageFolder folderAdded = await picturesLibrary.RequestAddFolderAsync();
if
(folderAdded !=
null
)
{
OutputTextBlock.Text = folderAdded.DisplayName +
" was added to the Pictures library."
;
}
else
{
OutputTextBlock.Text =
"Operation canceled."
;
}
}
}
}
//listfolder.cs
using
System;
using
Windows.Foundation.Collections;
using
Windows.Storage;
using
Windows.UI.Core;
using
Windows.UI.Xaml;
using
Windows.UI.Xaml.Controls;
using
Windows.UI.Xaml.Navigation;
namespace
SDKTemplate
{
public
sealed
partial
class
Scenario2 : Page
{
StorageLibrary picturesLibrary;
public
Scenario2()
{
this
.InitializeComponent();
}
protected
override
void
OnNavigatedTo(NavigationEventArgs e)
{
}
private
async
void
ListFoldersButton_Click(
object
sender, RoutedEventArgs e)
{
ListFoldersButton.IsEnabled =
false
;
picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
FoldersListView.ItemsSource = picturesLibrary.Folders;
picturesLibrary.DefinitionChanged += async (StorageLibrary innerSender,
object
innerEvent) =>
{
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
UpdateHeaderText();
});
};
UpdateHeaderText();
}
private
void
UpdateHeaderText()
{
FoldersListHeaderTextBlock.Text =
"Pictures library ("
+ picturesLibrary.Folders.Count +
" folders)"
;
}
}
}
//removefolder.cs
using
System;
using
Windows.Foundation.Collections;
using
Windows.Storage;
using
Windows.UI.Core;
using
Windows.UI.Xaml;
using
Windows.UI.Xaml.Controls;
using
Windows.UI.Xaml.Navigation;
namespace
SDKTemplate
{
public
sealed
partial
class
Scenario3 : Page
{
StorageLibrary picturesLibrary;
public
Scenario3()
{
this
.InitializeComponent();
this
.GetPicturesLibrary();
}
protected
override
void
OnNavigatedTo(NavigationEventArgs e)
{
}
private
async
void
RemoveFolderButton_Click(
object
sender, RoutedEventArgs e)
{
var folderToRemove = (StorageFolder)FoldersComboBox.SelectedItem;
if
(await picturesLibrary.RequestRemoveFolderAsync(folderToRemove))
{
OutputTextBlock.Text = folderToRemove.DisplayName +
" was removed from the Pictures library."
;
}
else
{
OutputTextBlock.Text =
"Operation canceled."
;
}
}
private
async
void
GetPicturesLibrary()
{
picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures);
FoldersComboBox.ItemsSource = picturesLibrary.Folders;
picturesLibrary.DefinitionChanged += async (StorageLibrary sender,
object
e) =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
UpdateControls();
});
};
UpdateControls();
}
private
void
FillComboBox()
{
FoldersComboBox.ItemsSource =
null
;
FoldersComboBox.ItemsSource = picturesLibrary.Folders;
}
private
void
UpdateControls()
{
FillComboBox();
bool
libraryHasFolders = (picturesLibrary.Folders.Count > 0);
FoldersComboBox.SelectedIndex = libraryHasFolders ? 0 : -1;
FoldersComboBox.Visibility = libraryHasFolders ? Visibility.Visible : Visibility.Collapsed;
LibraryEmptyTextBlock.Visibility = libraryHasFolders ? Visibility.Collapsed : Visibility.Visible;
RemoveFolderButton.IsEnabled = libraryHasFolders;
}
}
}
library
management
windows application