Urgent WebService
-
Below are my codes. I have created one webservice method to Upload the file. I access this webservice in my aspx file. It compile's fine. But it always return the result "2" What is wrong in my code? byte[] fileContent = null; FileStream fStream = null; string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = Path.GetFileName(strPath); int uploadStatus; fStream = new FileStream(strPath, FileMode.Open, FileAccess.Read); fileContent = new byte[fStream.Length]; fStream.Read(binFile, 0, (int)fStream.Length); uploadStatus = spService1.UploadAndApproveContent(strFileName, fileContent, 1); if (uploadStatus == 0) Response.Write("File has been UpLoaded"); else if (uploadStatus == 2) Response.Write("File doesn't Contain anything"); else Response.Write("File doesn't uploaded"); [WebMethod] public int UploadAndApproveContent(string fileName, byte[] fileContents ,int approvalStatus) { if (fileContents == null) { return 2; } try { fileName = "Tmp_" + fileName; SPWeb site = new SPSite(srcUrl).OpenWeb(); SPFile spFile = site.GetFile(srcUrl + "/" + fileName); SPFolder folder = site.GetFolder(srcUrl); if (isFileExists(fileName)) { spFile.CheckOut(); spFile.CheckedOutBy.LoginName.ToString(); } else { folder.Files.Add(fileName, fileContents, true); SPModerationInformation spModerationInformation = spFile.Item.ModerationInformation; switch (approvalStatus) { case 1: spModerationInformation.Status = SPModerationStatusType.Pending; spModerationInformation.Comment = "Its pending"; spFile.Item.Update(); return 0; case 2: spModerationInformation.Status = SPModerationStatusType.Approved; spModerationInformation.Comment = "Got the Approval"; spFile.Item.Update(); return 0; case 3: spModerationInformation.Status = SPModerationStatusType.Denied;
-
Below are my codes. I have created one webservice method to Upload the file. I access this webservice in my aspx file. It compile's fine. But it always return the result "2" What is wrong in my code? byte[] fileContent = null; FileStream fStream = null; string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = Path.GetFileName(strPath); int uploadStatus; fStream = new FileStream(strPath, FileMode.Open, FileAccess.Read); fileContent = new byte[fStream.Length]; fStream.Read(binFile, 0, (int)fStream.Length); uploadStatus = spService1.UploadAndApproveContent(strFileName, fileContent, 1); if (uploadStatus == 0) Response.Write("File has been UpLoaded"); else if (uploadStatus == 2) Response.Write("File doesn't Contain anything"); else Response.Write("File doesn't uploaded"); [WebMethod] public int UploadAndApproveContent(string fileName, byte[] fileContents ,int approvalStatus) { if (fileContents == null) { return 2; } try { fileName = "Tmp_" + fileName; SPWeb site = new SPSite(srcUrl).OpenWeb(); SPFile spFile = site.GetFile(srcUrl + "/" + fileName); SPFolder folder = site.GetFolder(srcUrl); if (isFileExists(fileName)) { spFile.CheckOut(); spFile.CheckedOutBy.LoginName.ToString(); } else { folder.Files.Add(fileName, fileContents, true); SPModerationInformation spModerationInformation = spFile.Item.ModerationInformation; switch (approvalStatus) { case 1: spModerationInformation.Status = SPModerationStatusType.Pending; spModerationInformation.Comment = "Its pending"; spFile.Item.Update(); return 0; case 2: spModerationInformation.Status = SPModerationStatusType.Approved; spModerationInformation.Comment = "Got the Approval"; spFile.Item.Update(); return 0; case 3: spModerationInformation.Status = SPModerationStatusType.Denied;
-
Below are my codes. I have created one webservice method to Upload the file. I access this webservice in my aspx file. It compile's fine. But it always return the result "2" What is wrong in my code? byte[] fileContent = null; FileStream fStream = null; string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = Path.GetFileName(strPath); int uploadStatus; fStream = new FileStream(strPath, FileMode.Open, FileAccess.Read); fileContent = new byte[fStream.Length]; fStream.Read(binFile, 0, (int)fStream.Length); uploadStatus = spService1.UploadAndApproveContent(strFileName, fileContent, 1); if (uploadStatus == 0) Response.Write("File has been UpLoaded"); else if (uploadStatus == 2) Response.Write("File doesn't Contain anything"); else Response.Write("File doesn't uploaded"); [WebMethod] public int UploadAndApproveContent(string fileName, byte[] fileContents ,int approvalStatus) { if (fileContents == null) { return 2; } try { fileName = "Tmp_" + fileName; SPWeb site = new SPSite(srcUrl).OpenWeb(); SPFile spFile = site.GetFile(srcUrl + "/" + fileName); SPFolder folder = site.GetFolder(srcUrl); if (isFileExists(fileName)) { spFile.CheckOut(); spFile.CheckedOutBy.LoginName.ToString(); } else { folder.Files.Add(fileName, fileContents, true); SPModerationInformation spModerationInformation = spFile.Item.ModerationInformation; switch (approvalStatus) { case 1: spModerationInformation.Status = SPModerationStatusType.Pending; spModerationInformation.Comment = "Its pending"; spFile.Item.Update(); return 0; case 2: spModerationInformation.Status = SPModerationStatusType.Approved; spModerationInformation.Comment = "Got the Approval"; spFile.Item.Update(); return 0; case 3: spModerationInformation.Status = SPModerationStatusType.Denied;
jayarajmrj wrote:
if (fileContents == null) { return 2; }
This is what is happening... The value of
fileContents
received by the webservice is null.jayarajmrj wrote:
fStream.Read(binFile, 0, (int)fStream.Length);
what is
binFile
? Shouldn't that be:fStream.Read(fileContent, 0, (int)fStream.Length);
instead?-- If this is a post that has been helpful to you, please vote for it. Thank you! "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." --Rich Cook
-
Below are my codes. I have created one webservice method to Upload the file. I access this webservice in my aspx file. It compile's fine. But it always return the result "2" What is wrong in my code? byte[] fileContent = null; FileStream fStream = null; string strPath = @"D:\XML Tutorial(Basics).doc"; string strFileName = Path.GetFileName(strPath); int uploadStatus; fStream = new FileStream(strPath, FileMode.Open, FileAccess.Read); fileContent = new byte[fStream.Length]; fStream.Read(binFile, 0, (int)fStream.Length); uploadStatus = spService1.UploadAndApproveContent(strFileName, fileContent, 1); if (uploadStatus == 0) Response.Write("File has been UpLoaded"); else if (uploadStatus == 2) Response.Write("File doesn't Contain anything"); else Response.Write("File doesn't uploaded"); [WebMethod] public int UploadAndApproveContent(string fileName, byte[] fileContents ,int approvalStatus) { if (fileContents == null) { return 2; } try { fileName = "Tmp_" + fileName; SPWeb site = new SPSite(srcUrl).OpenWeb(); SPFile spFile = site.GetFile(srcUrl + "/" + fileName); SPFolder folder = site.GetFolder(srcUrl); if (isFileExists(fileName)) { spFile.CheckOut(); spFile.CheckedOutBy.LoginName.ToString(); } else { folder.Files.Add(fileName, fileContents, true); SPModerationInformation spModerationInformation = spFile.Item.ModerationInformation; switch (approvalStatus) { case 1: spModerationInformation.Status = SPModerationStatusType.Pending; spModerationInformation.Comment = "Its pending"; spFile.Item.Update(); return 0; case 2: spModerationInformation.Status = SPModerationStatusType.Approved; spModerationInformation.Comment = "Got the Approval"; spFile.Item.Update(); return 0; case 3: spModerationInformation.Status = SPModerationStatusType.Denied;
By Default,when you do any update from code on sharepoint list item which has approval attached to it,it will be always be approved