Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Webpart classresource error!

  Asked By: Reginald    Date: Oct 19    Category: Sharepoint    Views: 1650

We have a problem of placing the class resource files. As our webpart
is complext webpart which is deal with database through webservice.

We have created a usercontrol web application. and through javascript
LoadService we get data. now, if we create this usercontrol to
webpart, where do we need to place the classresources. We have
followed the msdn document which says you need to place in wpresouces
of SPS if the assembly is placed on the bin directory. (I hope
including aspx pages,ascx files, javascripts, images should be placed
in Wpresources) I am not able to run the asmx file like
http://SPS/wpresources/myservice.asmx, only htm files are running
like http://sps/wpresources/error.htm.

Javascript loadwebservices still gives error since we place in in wpresouces.

I have tried with LoadControl(
'/wpresources/webapplication/usercontrol.ascx') and built also. still
gives problem.

Can somebody gives clue on how we have fix this issue?



1 Answer Found

Answer #1    Answered By: Lewis Mann     Answered On: Oct 19

This is not something that can easily be troubleshooted via email. Many things
go into making a User Control run as a class resource within the framework of a
Web Part. For starters:
-The Web Part should reference the User Control DLL
-The Web Part DWP should be deployed into \wpcatalog
-The Web Part DLL should be deployed into \bin
-The User Control DLL should be deployed into \bin
-The *.ascx file(s) should be deployed (as class resources) into
-The Page.LoadControl must reference a virtual path, however, I haven't found a
good way to convert from an absolute path like the ClassResourcePath to a root
relative path, so I roughly use the following code (hand typed untested C#):
//Get the root relative URL from the absolute ClassResourcePath URL by
//the first slash after the first eight characters (like https://)
string relativeURL = this.ClassResourcePath + "/MyUserControl.ascx"
relativeURL = relativeURL.Substring(relativeURL.IndexOf("/", 9));
userControl = this.Page.LoadControl(relativeURL);

That last line should result in a relativeURL like:
rather than:

OR if deployed to the 60 hive:
rather than:

If someone knows a better want to get the virtual path from an absolute path;
I'd be all ears.

I don't know why the code you presented wouldn't work:

It looks OK to me. I wouldn't want to hard code to the /wpresources/assemblyName
but it should work just the same.

I curious, if your Web Part is just displaying data, why not just use a Data
View Web Part (DVWP) to render the Web Service data?

Didn't find what you were looking for? Find more on Webpart classresource error! Or get search suggestion and latest updates.