Archive

Posts Tagged ‘.Net’

Generate word documents using OpenXML SDK

October 22, 2014 Leave a comment

Recently i came across a requirement that the application allows the user to generate the word documents for a specific report and they want the same data must follow some specific patterns .

So creating word document from scratch makes no sense and thus i forced to start look for other alternate options and came to know about OpenXML . But  only few limitted resources are available over the internet that explains the usage of this in a neat easy way fit perfect for begginers

http://www.dotnet-geek.co.uk/index.php/openxml-word-templates-processing/ 

and http://www.emoreau.com/Entries/Articles/2011/03/Using-OpenXML-to-fill-a-Word-document-from-a-Net-application.aspx

Both these are explain the concept using a desktop applicaton , but any one can easily convert it back to web app. In case th blog Urls are down can see the details of the blog in attached PDF

OpenXML Éric Moreau’s blog _ Using OpenXML to fill a Word document from a OpenXML Word templates processing _ dotNet Geek _

Advertisements
Categories: Prsnl References Tags: , ,

Customization on WPF ListView

June 5, 2013 2 comments

If  some one is planning to simply bind a list of datas to a listview in WPF its pretty easy and straight forward. But today i came through a case where i need a listbox that supports Sorting , Inline Editting and Save the chages to Db once i finish the inline edit .

I started one by one  1. Sorting and Inline Editting  > Using the logic or idea from this blog http://tech.pro/tutorial/857/wpf-tutorial-using-the-listview-part-3-in-place-edit

2. Saving the changes after finish the edit operation to Db – Add a new event to the textbox where you want to edit the data and do actions on that event

LostFocus=”textWordDescription_LostFocus” Tag=”{Binding}”

             string newtext = ((TextBox)sender).Text;
BindedObject selected = ((TextBox)sender).Tag as BindedObject;
updateDetails(selected.Id,selected);

Then next challenge is  want to sort my datas in ascending order . The following code solves that issue

  private void Sort(string sortBy, ListSortDirection direction)
{
ICollectionView dataView =
CollectionViewSource.GetDefaultView(wordBankListView.ItemsSource);
dataView.SortDescriptions.Clear();
SortDescription sd = new SortDescription(sortBy, direction);
dataView.SortDescriptions.Add(sd);
dataView.Refresh();
}

Next Challenge is with selection . By default i want to select an item in listbox (Its  pretty easy thing . just set selectedvalue ). But i need to handle the position of scrollviewer as well . If 100 items in listbox and i selected an item starts with letter z then thae item is in bottom of list , So using this code i make sure the scrollviewer position is closer to selected wordSystem.Windows.Controls.Primitives.Selector selector = wordBankListView;
(selector as ListBox).ScrollIntoView(selector.SelectedItem);

Categories: Prsnl References Tags: ,

Async. Download progress bar c#

December 4, 2012 Leave a comment

The code for creating an async. download progress bar , allows user to track how much data is downloaded

WebClient client = new WebClient();

client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);

client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

//// Starts the download

string folder_path =”Location to save file”;

client.DownloadFileAsync(new Uri(downloadUrl), folder_path,””);

void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)

{

double bytesIn = double.Parse(e.BytesReceived.ToString());

double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());

double percentage = bytesIn / totalBytes * 100;

 

downloadProgress.Text = int.Parse(Math.Truncate(percentage).ToString()).ToString()+” % finished”;

}

Categories: Prsnl References Tags: , , , ,