- Search SharePoint Legacy Versions - Development and Other Programming Forum
- Search All SharePoint Products and Technologies Forums
- Search All MSDN Forums
-
Tuesday, April 14, 2009 6:44 PMda.3vil.genius
da.3vil.genius
65 Points 2 0 0Recent AchievementsForums Answerer I First Marked Answerda.3vil.genius's threads View Profile0Hello,
I'm trying to programmatically upload a file to a sharepoint list but keep getting the following error:
The Web application at http://mysite.site.com/sites/appdevelop/Project%20Plans/Forms/AllItems.aspx?RootFolder=%2fsites%2fappdevelop%2fProject%20Plans%2fExternal%20Website 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.
Here's the code I'm using (C#):
private void UploadFileToSharePoint(string strInputFileName) { string destUrl = ConfigurationManager.AppSettings["destURL"]; string destFileUrl = destUrl + "/New.txt; SPWeb site = new SPSite(destUrl).OpenWeb(); site.AllowUnsafeUpdates = true; FileStream fileStream = File.Open(strInputFileName, FileMode.Open); site.Files.Add(destFileUrl, fileStream, true/*overwrite*/); fileStream.Close(); }
Can anyone tell me where I'm going wrong?
Thanks in advance.- Reply
- Quote
Answers
-
Wednesday, April 15, 2009 8:00 AMmanish parab
manish parab
Ag technologies
Partner
85 Points 6 0 0Recent AchievementsForums Replies I First Marked Answer Forums Answerer Imanish parab's threads View ProfileAg technologies(Partner)85 Points0I have Modified your function a little bit..this is how it looks
private void UploadFileToSharePoint(string strInputFileName,string sDocLibraryName) { string destUrl = ConfigurationManager.AppSettings["destURL"]; SPWeb site = new SPSite(destUrl).OpenWeb(); SPList myList = site.Lists[sDocLibraryName]; string destFileUrl = myList.RootFolder.ServerRelativeUrl + @"/New.txt"; site.AllowUnsafeUpdates = true; FileStream fileStream = File.Open(strInputFileName, FileMode.Open); site.Files.Add(destFileUrl, fileStream, true/*overwrite*/); fileStream.Close(); }
Call To this Function Would Be
UploadFileToSharePoint(@"C:\Ids.txt", "strore 102"/* name of Dc Library*/);
Hope This Helps
regards
Manish
http://mnish.blogspot.com/- Marked As Answer by da.3vil.genius Wednesday, April 15, 2009 3:39 PM
- Reply
- Quote
All Replies
-
Tuesday, April 14, 2009 6:52 PMSteve.Curran MVP
Steve.Curran MVP
KnowledgeLake
Partner, MVP
29,435 Points 10 4 2Recent AchievementsProfile Complete Proposed Answerer I Forums Replies IVSteve.Curran MVP's threads View ProfileKnowledgeLake(Partner, MVP)29,435 Points0Try just using http://mysite.site.com/sites/appdevelop/Project%20Plans when constructing your SPSite object
http://www.certdev.com- Reply
- Quote
-
Tuesday, April 14, 2009 7:28 PMda.3vil.genius
da.3vil.genius
65 Points 2 0 0Recent AchievementsForums Answerer I First Marked Answerda.3vil.genius's threads View Profile0Nope, still the same error.
- Reply
- Quote
-
Tuesday, April 14, 2009 7:56 PMSathish TK
Sathish TK
Partner
95 Points 3 0 0Recent AchievementsFirst Answer Confirmed Forums Answerer I First Forums ReplySathish TK's threads View Profile(Partner)95 Points0Are you getting this error in anonymous mode or signed-in?
Check the permissions on your list and ensure the proper user group can add new items to the list.
In the code trying using RunWithElevatedPrivileges of the SPSecurity class (note: this is not the recommended approach)
http://www.sathishtk.com/blog- Reply
- Quote
-
Tuesday, April 14, 2009 8:43 PMMoonis Tahir
Moonis Tahir
MCC, Partner
8,500 Points 12 3 1Recent AchievementsProfile Complete Forums Answerer IV Proposed Answerer IMoonis Tahir's threads View Profile(MCC, Partner)8,500 Points0where you are running your code, on sharepoint box Or on your development box trying to upload to a different sharepoint server? as long as you have permissions to the web and your code is running on sharepoint Box, there should be no issue in creating SPSite object. you can create SPSite object in RunWithElevatedPrivilage block.
Moonis Tahir MCSD.net, MCTS Sharepoint 07 (Dev & Config), MCTS BizTalk 06, MCTS SQL 2005.- Reply
- Quote
-
Tuesday, April 14, 2009 9:09 PMDave Hunter
Dave Hunter
Portaltech Consulting Li...
Partner, MVP
20,310 Points 11 4 1Recent AchievementsProposed Answerer I Forums Answerer IV Forums Replies IVDave Hunter's threads View ProfilePortaltech Consulting Li...(Partner, MVP)20,310 Points0You need to use http://mysite.site.com/sites/appdevelop in your new SPSite(). Project Plans is your document library.
The following should work
privatevoid UploadFileToSharePoint(string strInputFileName)
{
string destUrl = http://mysite.site.com/sites/appdevelop;
string destFileUrl = destUrl + "project%20plans" + "/New.txt;
using(SPWeb site = new SPSite(destUrl).OpenWeb())
{
site.AllowUnsafeUpdates = true;
FileStream fileStream = File.Open(strInputFileName, FileMode.Open);
site.Files.Add(destFileUrl, fileStream, true/*overwrite*/);
fileStream.Close();}
}Hope this helps
Dave
My SharePoint Blog - http://www.davehunter.co.uk/blog- Reply
- Quote
-
Wednesday, April 15, 2009 8:00 AMmanish parab
manish parab
Ag technologies
Partner
85 Points 6 0 0Recent AchievementsForums Replies I First Marked Answer Forums Answerer Imanish parab's threads View ProfileAg technologies(Partner)85 Points0I have Modified your function a little bit..this is how it looks
private void UploadFileToSharePoint(string strInputFileName,string sDocLibraryName) { string destUrl = ConfigurationManager.AppSettings["destURL"]; SPWeb site = new SPSite(destUrl).OpenWeb(); SPList myList = site.Lists[sDocLibraryName]; string destFileUrl = myList.RootFolder.ServerRelativeUrl + @"/New.txt"; site.AllowUnsafeUpdates = true; FileStream fileStream = File.Open(strInputFileName, FileMode.Open); site.Files.Add(destFileUrl, fileStream, true/*overwrite*/); fileStream.Close(); }
Call To this Function Would Be
UploadFileToSharePoint(@"C:\Ids.txt", "strore 102"/* name of Dc Library*/);
Hope This Helps
regards
Manish
http://mnish.blogspot.com/
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentlegacy/thread/c99e6161-66e9-4aea-953a-16f64f816cd7
-
Hi,
i want to upload a document which is in local path, and if the document is already available, it should create a new version for the document.
in API, SPfolder.Files.add method is having Overwrite option, i am not able to see the option to create version and all.
Please guide me , Thanks in advance.
- Reply
- Quote
Answers
-
Wednesday, January 12, 2011 5:41 AMHemendra Agrawal
Hemendra Agrawal
Wartsila
Partner
21,190 Points 20 6 2Recent AchievementsCode Answerer III New Blog Rater New Blog CommentatorHemendra Agrawal's threads View ProfileWartsila(Partner)21,190 Points0Hi,
Thanks for reply. You need to write small algorithm to generate version.
1. Check file whether it is existing or not
2. If it is existing then CheckOut your file and CheckIn it
Like this: SPListItem.File.CheckOut / SPListItem.File.CheckIn
This will create new version of your item.
Hope this could help
Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"- Marked As Answer by KeFang Chen Monday, January 17, 2011 7:52 AM
- Reply
- Quote
-
Wednesday, January 12, 2011 9:45 AMAmit.AK.Kumar
Amit.AK.Kumar
Partner
1,350 Points 10 2 0Recent AchievementsForums Replies III Proposed Answerer I First Helpful VoteAmit.AK.Kumar's threads View Profile(Partner)1,350 Points0Please try this:
destinationFolder.Files.Add(destinationFileURL, filebytes,sourceFile.Properties, true);
Thanks, Amit Kumar, LinkedIn Profile ** My Blog- Marked As Answer by KeFang Chen Thursday, January 27, 2011 3:32 AM
- Reply
- Quote
All Replies
-
Tuesday, January 11, 2011 11:07 AMHemendra Agrawal
Hemendra Agrawal
Wartsila
Partner
21,190 Points 20 6 2Recent AchievementsCode Answerer III New Blog Rater New Blog CommentatorHemendra Agrawal's threads View ProfileWartsila(Partner)21,190 Points0Hi,
Try this:
SPfolder.Files.add(filename, content, false );
You may be refer this also:
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/c99e6161-66e9-4aea-953a-16f64f816cd7/
Let us know your result
Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"- Reply
- Quote
-
Wednesday, January 12, 2011 5:25 AMAkilaskk
Akilaskk
40 Points 4 0 0Recent AchievementsForums Answerer I First Helpful Vote First Forums ReplyAkilaskk's threads View Profile0hi,
Thanks for your response,
i was trying like,
SPfolder.Files.add(filename, content, false );
but it shows , A file with the name "spfolder/hello.txt" already exists.
i have enabled versioning in the SPfolder too.
Please guide me. thanks in advance
- Reply
- Quote
-
Wednesday, January 12, 2011 5:41 AMHemendra Agrawal
Hemendra Agrawal
Wartsila
Partner
21,190 Points 20 6 2Recent AchievementsCode Answerer III New Blog Rater New Blog CommentatorHemendra Agrawal's threads View ProfileWartsila(Partner)21,190 Points0Hi,
Thanks for reply. You need to write small algorithm to generate version.
1. Check file whether it is existing or not
2. If it is existing then CheckOut your file and CheckIn it
Like this: SPListItem.File.CheckOut / SPListItem.File.CheckIn
This will create new version of your item.
Hope this could help
Cheers, Hemendra-MCTS "Yesterday is just a memory,Tomorrow we may never see"- Marked As Answer by KeFang Chen Monday, January 17, 2011 7:52 AM
- Reply
- Quote
-
Wednesday, January 12, 2011 9:45 AMAmit.AK.Kumar
Amit.AK.Kumar
Partner
1,350 Points 10 2 0Recent AchievementsForums Replies III Proposed Answerer I First Helpful VoteAmit.AK.Kumar's threads View Profile(Partner)1,350 Points0Please try this:
destinationFolder.Files.Add(destinationFileURL, filebytes,sourceFile.Properties, true);
Thanks, Amit Kumar, LinkedIn Profile ** My Blog- Marked As Answer by KeFang Chen Thursday, January 27, 2011 3:32 AM
http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopmentlegacy/thread/1f003923-dc88-427b-a6b8-34c3616d5b1a