Dailycode.info

Short solution for short problems

Dilbert on SharePoint

You want to encourage users to check a certain WSS site, use dilbert as an attraction.

This nice enterprise cartoon changes everyday and give a laugh now and then. It generates extra motivation for users to daily check the site.

To place it on your site is really easy. Just go to this site, download the webpart and import it to your site. Thats it really.

 


Unlink a list item from source item

When you use the Copy method, to copy a list item from one list to another, the item is linked automatically to the source item. This enables the user to go to the source item, even if we don't like it.

the solution is to unlink the item. This can be done manually, but when you copy using coed, you can directly unlink the item like this:

SPListItem.Copy(SPContext.Current.Web.Url + "/" + _doc.Url, _publicLibUrl + _doc.Name);
SPListItem fileToUnlink = site.AllWebs[_publicSiteName].GetListItem(_publicLibUrl + _doc.Name);
if (fileToUnlink != null)
{
fileToUnlink.UnlinkFromCopySource();
fileToUnlink.Update();}

The first try I forgot to add the .Update(). It is required to to this, if not, your change is not updated and the item is not unlinked. The unlinking cannot be undone.


Directory structure generator version 1.1

I made some adjustements to the directory structure generator which have lead to new version. The major change is that I do the generation in a seperate thread. Now I can update the info during the process, the main thread is not blocked. It is also possible to stop the porcess whenever you like.

I added some extra features which can be nice. E.g. sorting on date, show modifydate in result, ...

Here is a screenshots of the latest version:

The exe file and source files can be requested.

You can read here how it all started.

 


Free movie, CD and books database part 2

The first version is almost ready to be published. Here's a screenshot of the configuration part.

As you can see, you can select an automatic backup. You can manually backup and restore files. Also you can disable functions, for example if you are not using the movie database:

Only the tesing fase and then the first version will be released. When you are using them, all data is stored in a format that is supported for future versions. so start using it as soon as it becomes available. then you can get the new version just as free as you are getting this one!

Read part 1.


Self updating windows program part 2

In part 1 I explained how to write and implement a self updating windows program. The functionality was simple. Just before I close the program to be updated, I open the “update.bat“ file. Then I close the program. The bat file first pings to create a delay and after the ping it copies the new files to the directory. When its finished it will open the application again.
 
Because the interaction with the user is not so great, although I did not receive any complaints, I decided to improve this part of the application.
 
After some thinking I came up with the idea to create an updater program which can be used for multiple programs. So it had to be configurable.
 
 
 
The only thing you have to do is to copy the updater.exe and its configuration file to your solution. Make sure it is copied to the bin folder. Just add it to your solution and right-click on the files and choose properties. Then you will see the property copy to output directory. Set this property to: Copy always. Then you fill in the path in the configuration file. The configuration file could look something like this:
 
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="UpdateFilesPath" value="\\fileserver\updates\myprogram\latestversion\"/>
  </appSettings>
</configuration>
 
Then in the directory where the new files are placed, you’ll have to add an XML file called:updateInfo.xml with the following format:
 
<?xml version="1.0" standalone="yes"?>
<UpdateInfoDS xmlns="http://tempuri.org/UpdateInfoDS.xsd">
  <UpdateInfo>
    <ApplicationName>MyProgram</ApplicationName>
    <NewVersion>2.1.1.2</NewVersion>
    <ExtraInfo>Test version for update</ExtraInfo>
    <DeletePrevVersion>false</DeletePrevVersion>
  </UpdateInfo>
</UpdateInfoDS>
 
So here we can set the parameters of the updater. The new version and extra info parameters are simply to inform the user during update about what is being updated. The application name is shown on the tool as well, but is also used to check if the program to be updated is still in use. So it is important this is exactly the same is the exe you are trying to update.
The delete previous version (DeletePrevVersion) parameter is like it suggests: deleting all the files of the previous version.
 
To check if a new version is needed and to start the updater is similar as in part 1, but I will explain it again:
 
Because I’m working on a network with a database, I’ll check the database for a new version:
 
Assembly asm = Assembly.GetExecutingAssembly();
//Check registration and version
if (CheckRegistration(asm.GetName().Version.ToString()))
  
If there is a newer version then the current version of the program I will start an update:
 
System.Diagnostics.Process.Start(Application.StartupPath + @"\Updater.exe");
 
After I started the updater program, I’ll write some information to the database and close the application. The updater will wait until the program is closed until it starts the update.
This check is performed like this:
 
bool into = false;
string updatePath = ConfigurationSettings.AppSettings["UpdateFilesPath"];
int counter = 0;
while (!into)
{
    try
    {
        File.Copy(updatePath + @"\" + appName + ".exe", appName + ".exe", true);
        into = true;
    }
    catch
    {
        if (counter > 10)
        {
            return;
        }
        else
  {
            System.Threading.Thread.Sleep(500);
            counter++;
        }
    }
}
 
 
The deletion an copying of the files are done in a seperate thread, so it doesn't interfear with the GUI. The progress is set with thread safe methods. Before the update starts, I count the number of files to be copied and use this to set the progress bar limit. So it will give you a windows like information, if there is a files in the upload that is much bigger then the rest, the progress will not be as accurate. But still it give a better view then nothing, or just a wiating arrow.
When the copy is successful the program will go on to copy all files and if requested first delete all old files. The only files that are not deleted and copied over are the files of the updater itself. So it is really important that your updater is working really good and tested through several times. The update files have to be on the network, I'm currently working on an update of this program that enables you to place the update files on the internet. Then I should rewrite the File.Copy part.
 
That’s why I look at the updater not as a part of any solution but a separate program that can be used throughout all kinds of windows applications.
 
 

 


Directory structure generator

Many people have a certain logic in the way they build up their files system, and so they should. Sometimes you want to view this structure or export it because you want to use it for some kind of purpose. Then you will have a hard time in windows getting the structure in an organized way to a file or excel sheet.

 

For this reason I created a tool that helps you export a directory structure. It started out just exporting the structure if the directories and files, but now you can use checkboxes to add more information to the export.

You can:

  • Choose to see only file or dir names or the complete path.
  • Choose the depth of the search. (0 is only the root directory) 
  • Choose to show the size of the files.
  • Then for extra information on the top right you can see the number of files and directories that are shown. 

There is a new version available for download. You can find more info here in part 2. 

You can download this project latest version as an executable and/or the source files to get the function you need out of it.

 

 

 

 


Using Oracle client 32 bit on a 64 bit computer

I created an application that uses oracle client to connect to the database. Never had any troubles with this until a new workstation arrived with a 64 main board. We installed and configured the Oracle client 32 bit. There are some tricks to this, if you need to know just ask. When I attempted to open the application, I got this error:

When I deployed the application on this workstation I got the following error:Attempt to load Oracle client libraries threw BadImageFormatException. This problem will occur when running in 64 bit mode with the 32 bit Oracle client components installed. 

   

The reason was my application was compiled for the platform target: Any CPU. I had to change this the x86 and then the application works. You can change this in the properties window of your application on the build section.