Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I created document using office XML but now i m going to store that document in sharepoint library then it giving me an error like ["The Web application at {siteUrl} could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."]

...Note that i have asp.net web application running on the same server where sharepoint running. I have added Microsoft.Sharepoint to my asp.net application but when i going to create the object of SPSite then it giving me this error.

Here is Code...

Using memStream As MemoryStream = New MemoryStream()
            Using doc As WordprocessingDocument = WordprocessingDocument.Create(memStream, DocumentFormat.OpenXml.WordprocessingDocumentType.Document, True)
                doc.AddMainDocumentPart()
                doc.MainDocumentPart.Document = New Document(New Body(New Paragraph(New Run(New Text("Hello")))))
                doc.MainDocumentPart.Document.Save()
            End Using

            Using Site As SPSite = New SPSite("http://sspl:5555/")
                Dim docLib As SPList = Site.RootWeb.Lists("Doc")
                Dim file As SPFile = docLib.RootFolder.Files.Add("Test.docx", memStream, True)
                file.Update()
            End Using

        End Using

Your reply appreciated. Thanx

share|improve this question
    
Have you verified that you can enter the URL in a browser and reach the site? Do the user your using have permission to access the site? –  Robban1980 Aug 16 '12 at 5:33
    
@Robban1980 Yes..!! Robban...whenever i going to access it form browser it works fine. And I am logged in with administrator on the server who has full rights on the site. –  Jugal Kundal Aug 16 '12 at 6:11
    
I don't know if your using impersonation on your ASP.Net site, if your not the application will run under the ApplicationPool account. That probably don't have access to your SharePoint site. Have you tried running it with elevated privileges i.e. SPSecurity.RunWithElevatedPrivileges(delegate() { // implementation details omitted }); ? It could also be that you application has a hard time resolving the sspl URL. is the sspl:5555 address in the Alternative Access mapping? Are you using Host headers on the IIS site? –  Robban1980 Aug 16 '12 at 6:21
    
i face the same problem if you solve this let me know. Thanks –  Hiren Aug 27 '12 at 12:12
add comment

3 Answers

if your application run inside sharepoint site then you use object model but if you use your asp.net application not in sharepoint site then you have to use client object model not object model so u get error in SpSite object.

if your application run in sharepoint site then there is a problem of permission

write your code inside

SPSecurity.RunWithElevatedPrivileges(delegate()
{
// implementation details omitted
});
share|improve this answer
    
Hi V_B, @V_B : would you please provide me code of delegate for vb.net..?? –  Jugal Kundal Aug 20 '12 at 4:27
    
As you suggest i used client object model to upload document. it work perfectly when i run the program in debug mode but when i host it to IIS then it giving me an error (401: Unauthorized).@Ketan03 –  Jugal Kundal Aug 20 '12 at 4:42
    
Hi @jkundal u have to apply Credentials like so ctx.Credentials = new System.Net.NetworkCredential("username", "password", "domain"); –  Vishal_Sharepoint Aug 20 '12 at 6:09
    
@jkundal when we use client object model we can't use runwithelevated –  Vishal_Sharepoint Aug 20 '12 at 6:18
    
So what i need to do to resolve this (401:Unauthorized) error.?? @V_B –  Jugal Kundal Aug 20 '12 at 6:30
show 2 more comments

is this a console application/ If yes...please check the .Net Framekwork and Build-CPU settings

Build should be set to x64 bit CPU and .Net Framwork should be set to 3.5

Thanks, Ketan

share|improve this answer
    
No Ketan it's not a console application i mentioned that it is my other **asp.net web application** @Ketan03 –  Jugal Kundal Aug 16 '12 at 5:30
add comment

Is it deployed in IIS or you are using the Visual Studio Internal Websever (running the asp.net app using visual studio ) ??

Firstly, Visual Studio is not 64 bit and Sharepoint binaries are 64 bit, as the Visual Studio WebDev WebServer is 32 bit, it raises this stupid exception :)

If this exception still occurs when u deployed it in IIS, then check the AAM settings for the Application

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.