SharePoint Blog - René Hézser

Anmelden  RSS Feed RSS Feed
Startet die Suche

Archive

Kategorien

Links

Andere Blogs



Add to Technorati Favorites

Mar 302008

Access Fileserver Data via SharePoint

Update:
The Webpart is not (yet) working as expected. Ajax only works for postbacks. The initial load will take longer, if you have many directories. I am working on this...

Update2:
Almost done! Ajax is working fine. Ajax is registered, so you don't need to modify the web.config yourself.
Todo: Performance.
Hang on just a little more.

Update3:
Done. I have worked on my Webpart. It will now be faster and it is working :-)
If you have previously installed the Webpart, please uninstall it, and reinstall again. You can use the setup program.

I guess everybody knows this scenario. You are with a customer or at home, and need a file from your company's fileserver very badly. What can you do? VPN is not possible, and you can't phone a colleague who can then send you the file via email because nobody is in the office. Don't bother any more. The solution is here J

With my Webpart you can access files from e.g. your fileserver via SharePoint / Browser.

All you have to do is install the solution, activate and deploy it. When you drag the Webpart onto a SharePoint page, you configure the root path from which you want to share data, and your users are able to download the files through the Webpart.

All files and folders are security trimmed. Meaning you can only download files and see folders, which you would see on the directory itself.

Of course this Webpart is translated to English and German. If you want it in your language, contact me.

Sorting the four columns allows your users to find the files they are searching more quickly. The paging size can be configured in the Webpart properties.

This Webpart requires the .Net Framework 3.5 on your WFE (Web Front End) Servers and you have to modify your web.config files to use AJAX. There is an Installation guide here. Be careful to change the version number from Version=1.0.61025.0 to Version=3.5.0.0!

Installation:

After you have added the solution via stsadm, you have to activate the feature on your webapplication and site collection.

Update:

The Webpart can now be installed with a setup program. It will automatically adjust your web.config, so you don't have to manually put in all AJAX configuration elements.

Before you activate the feature on your sitecollection, activate the feature for the web application in the central administration. This will do all steps for you.

Update 5.6.08:

A small update. Added danish language support (thx to Anja!) and a small performance tuning.

Update 19.6.08:

A small update. Installing the solution via installer does not work as expected. So I will have removed the installer, and uploaded a plain old wsp.

Update 29.9.09

If you are running your SharePoint Farm on a Windows Server 2008, you might want to read this KB article. I is titled "You cannot upload files that are larger than 28 MB on a Windows Server 2008-based computer that is running Windows SharePoint Services 3.0"

Download the solution here

Technorati Tags: ,,

Mar 292008

Custom Formatting in a SPGridView

One of the problems with the SPGridView occurs, if you display e.g. the file size of files, and try to sort with this information. The internal value you get from a SPFile of FileInfo Object shows you the length of the file in bytes. This is great if you want to sort this column. But what if you choose to display the long value with the amount of bytes for a file not as the value, but formatted with SPUtility.FormatSize(file.length)?

Well, you cannot sort for this column anymore, because sorting System.string values is not the same as sorting the original file size which is a System.long.

So what can you do to a) format the file size nicely and b) still be able to sort your entries with their file sizes?

  1. Create a new class with a custom format method
  2. Add a DataColumn to your DataTable
    _DataTable.Columns.Add("Size", typeof(FileSize));
  3. Create a BoundField and add it to your SPGridView
  4. Add a new DataRow to your DataTable
    row["Size"] = new FileSize(file.Length);

If you look at my FileSize class you will notice that I am overriding the .ToString() method with a PadLeft. This is due to the fact that a string sorting is not the same as sorting a long. But if you put zeros in front of the long and then sort the resulting string, you will get the desired sorting.

The big TODO with this solution is, that you have to disable the filtering for the "Size" column. This is due to the fact that we use our own class in the DataTable, which does not work with the FilteredDataSourcePropertyFormat = "{1} LIKE '{0}'" from the SPGridView, because it is not a string. "System.Data.EvaluateException: Cannot perform 'Like' operation on RH.FileLink and System.String"

new class

   1:  class FileSize : IFormattable
   2:  {
   3:      private readonly long _Value;
   4:   
   5:      public long Value
   6:      {
   7:          get { return _Value; }
   8:      }
   9:   
  10:      public FileSize(long value)
  11:      {
  12:          _Value = value;
  13:      }
  14:   
  15:      public override string ToString()
  16:      {
  17:          //fill trailing zeros to be able to sort the size correctly
  18:          string value = _Value.ToString().PadLeft(12);
  19:          return value;
  20:      }
  21:   
  22:      // Write a custom Format method which shows the filesize "nicely"
  23:      public string ToString(string format, IFormatProvider fp)
  24:      {
  25:          if (format.Equals("nice"))
  26:              return SPUtility.FormatSize(_Value);
  27:          else 
  28:              return _Value.ToString(format, fp);
  29:      }
  30:  }
 

BoundField

   1:  BoundField size = new BoundField();
   2:  size.DataField = "Size";
   3:  size.HtmlEncode = false;
   4:  size.HeaderText = "Size";
   5:  size.SortExpression = "Size";
   6:  // use custom formatting, to display 1Kb instead of 1024
   7:  size.DataFormatString = "{0:nice}";
   8:   
   9:  _GridView.Columns.Add(size);
 
Update 24. March 2009
Filtering can be adjusted by changing the "FilteredDataSourcePropertyFormat" property to "{1}='{0}'";
Thanks to Volker for this one.
 
 
Technorati Tags: ,,
 

Published: 3/29/2008  7:03 PM | 1  Comment | 0  Links to this post
Tagged as: Development, SharePoint

Mar 292008

Permissions Webservice and the Mask Attribute

With the SharePoint Permissions Webservice you can get the Permissions from a List or Web. The Webservice returns information like this example from the WSS SDK:

   1:  <GetPermissionCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/">
   2:     <Permissions>
   3:        <Permission MemberID="1073741829" Mask="-1" MemberIsUser="False" MemberGlobal="False" 
   4:           RoleName="Administrator" />
   5:        <Permission MemberID="1073741828" Mask="1029638927" MemberIsUser="False" MemberGlobal="False" 
   6:           RoleName="Web Designer" />
   7:        <Permission MemberID="1073741827" Mask="1027801615" MemberIsUser="False" MemberGlobal="False" 
   8:           RoleName="Contributor" />
   9:        <Permission MemberID="1073741826" Mask="138608641" MemberIsUser="False" MemberGlobal="False" 
  10:           RoleName="Reader" />
  11:        <Permission MemberID="1073741825" Mask="134283264" MemberIsUser="False" MemberGlobal="False" 
  12:           RoleName="Guest" />
  13:        <Permission MemberID="1073741830" Mask="134414337" MemberIsUser="False" MemberGlobal="False" 
  14:           RoleName="Site_Group1" />
  15:        <Permission MemberID="1073741831" Mask="134283265" MemberIsUser="False" MemberGlobal="False" 
  16:           RoleName="Site_Group2" />
  17:           .
  18:           .
  19:           .
  20:  </GetPermissionCollection>

 

If you want to convert the Mask to readable SPBasePermissions objects, the answer is:

   1:  SPBasePermissions permissions = 
   2:  (SPBasePermissions) Enum.Parse(typeof (SPBasePermissions), permissionMask.ToString());

 

Quite simple. Isn't it?

Keywords: SharePoint, Webservice, Permissions, Mask, GetPermissionCollection


Published: 3/29/2008  6:58 PM | 0  Comments | 0  Links to this post
Tagged as: SharePoint

Mar 122008

EventHandler which sends an Email for new/changed items

What do you do if you want to be alerted for changes in a list?

Right. You set an alert. Or you can create a workflow with your SharePoint Designer. But there is a different way. With my "RH.ItemNotifier" Feature, you can configure alerts through the settings of a list.

Configure Users which need to be emailed for new items or changes to existing ones.

So why would you use this solution to create alerts? Well, you don't :-)
I created this as a proof of concept with some functionality which might come handy sometimes:

  • EventReceiver for lists/document libraries
  • Send an Email through the SharePoint OM
  • Deactivate a feature on all webs in your farm
  • Build a custom aspx page in your layouts folder to handle the user configuration

Feel free to look into the code, and take what you need.

Download Download the sourecode here
Download Download the SharePoint solution here


Published: 3/12/2008  6:43 PM | 3  Comments | 0  Links to this post
Tagged as: Development, SharePoint