Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Urgent WebService

Urgent WebService

Scheduled Pinned Locked Moved ASP.NET
questionxmltutorialannouncement
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jayarajmrj
    wrote on last edited by
    #1

    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;

    K T U 3 Replies Last reply
    0
    • J jayarajmrj

      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;

      K Offline
      K Offline
      kubben
      wrote on last edited by
      #2

      Well based off your code your fileContents byte array must always be null. If you are always return 2 from your method call. Ben

      1 Reply Last reply
      0
      • J jayarajmrj

        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;

        T Offline
        T Offline
        Talal Sultan
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • J jayarajmrj

          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;

          U Offline
          U Offline
          User 1441925
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups