Welcome to deBUG.to Community where you can ask questions and receive answers from Microsoft MVPs and other experts in our community.
0 like 0 dislike
1.7k views
in SharePoint Server by
edited by anonymous

I am trying to create a new Visual WebPart in SharePoint Server with a Resource file that deployed in the Global Resource folder App_GlobalResources, but the problem is I can't use a resource key in the frond HTML code of my SharePoint Visual WebPart as below

<div class="col-md-3">
 <label for="username" class="form-label">
	<asp:Literal runat="server" Text="<%$Resources:ResourceFile,FullName%>"/></label>
</div>

When I perform build for the SharePoint solution, I get this error "The ResourceFile Name does not exist in the current context"! Although I already have three resources files in the same project with the correct name and correct resource key! How can I use the resource file in the Visual web part without facing this error?

BTW, I checked this link but it doesn't help me to solve my issue?


1 Answer

0 like 0 dislike
by 158 184 367
selected by anonymous
 
Best answer

Solving: The Resource does not exist in the current context

I faced this error before and the solution was using Visual WebPart (Farm solution only) instead of using Visual WebPart as below:

Solving: The Resource does not exist in the current context

In your case, I would suggest doing the following:

  1. Make sure that the Resource file is already deployed and located App_GlobalResources OR Mapped Resources Folder and Config Resources Folder on all SharePoint Server across your farm.
    • App_GlobalResources Path: C:\inetpub\wwwroot\wss\VirtualDirectories
    • SharePoint Root Resource Folder Path: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\Resources
    • Config Resources Folder Path: C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\CONFIG\Resources

      Note: the SharePoint Root Resource Folder used for all Pages, Controls, and Web Parts, and Config Resources Folder used for Features, Site Definitions, List Definition, Content Types

  2. Make sure that you have provided the correct Resource Filename with the correct Key.
  3. Make sure that the current solution is a farm solution and the current web part is Visual Web Part (Farm Solution Only).
  4. If you did all previous checks and still can't use the Resource file in your SharePoint Visual WebPart, I would suggest setting the Resource Key to your ASP Control using C# as below

     Label1.Text = HttpContext.GetGlobalResourceObject("ResourceFile", "ResourceKey").ToString();
    

See Also

If you don’t ask, the answer is always NO!
...