1

The newly created web part is working fine on local server but after deployed on the another server it is not working.Mainly the request is not going to the server when clicked on the submit button.Web part image

enter image description here

HTML code:

<div class="form-group">
    <div class="col-lg-offset-3 col-md-offset-3 col-sm-offset-3 col-lg-9 col-md-9 col-sm-9 col-xs-12">
        <asp:Button ID="btnEditWI" class="btn btn-custom" runat="server" Text="Submit" OnClick="EditWIUpload_Click" ValidationGroup="submitEdit"/>
        <input id="cancelEditWI" type="button" value="Cancel" class="btn btn-custom" name="Cancel" data-dismiss="modal" CausesValidation="false" />
    </div>
</div>

Server side code:

protected void EditWIUpload_Click(object sender, EventArgs e)
    {
        bool isValidate = validateForm();
        bool isCheckListIdExists = checkListExists();
        if (isValidate)
        {
            try
            {
                using (SPSite site = new SPSite(SPContext.Current.Web.Url))
                {

                    using (SPWeb web = site.OpenWeb())
                    {

                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            if (fuWorkInstruction.HasFile)
                            {

                                SPDocumentLibrary documentLib = web.Lists["WorkInstruction"] as SPDocumentLibrary;
                                SPFileCollection files = documentLib.RootFolder.Files;
                                SPListItem chkItem = documentLib.GetItemById(strCheckListID);
                                string strChkId = chkItem["WorkInstructionID"].ToString();
                                chkItem.Delete();
                                Stream fStream = fuWorkInstruction.PostedFile.InputStream;
                                byte[] _byteArray = new byte[fStream.Length];
                                fStream.Read(_byteArray, 0, (int)fStream.Length);
                                fStream.Close();

                                web.AllowUnsafeUpdates = true;

                                Random rnd = new Random();
                                int fileRnd = rnd.Next(1000);

                                string fileExt = Path.GetExtension(fuWorkInstruction.PostedFile.FileName);
                                string fileName = Path.GetFileNameWithoutExtension(fuWorkInstruction.PostedFile.FileName) + fileRnd;
                                string _fileUrl = fileName + fileExt;


                                //string _fileUrl = documentLib.RootFolder.Url + "//" + fuWorkInstruction.PostedFile.FileName;
                                //string _fileUrl = Path.GetFileName(fuWorkInstruction.PostedFile.FileName);

                                bool IsOverwriteFile = true;
                                //SPFile file = documentLib.RootFolder.Files.Add(_fileUrl, _byteArray, IsOverwriteFile);

                                SPFile newFile = files.Add(documentLib.RootFolder.Url + "/" + _fileUrl, _byteArray, IsOverwriteFile);
                                SPList documentLibraryAsList = web.Lists["WorkInstruction"];
                                SPListItem item = documentLibraryAsList.GetItemById(newFile.ListItemAllFields.ID);



                                if (isCheckListIdExists)
                                {
                                    item["WorkInstructionID"] = strChkId;
                                }
                                else
                                {
                                    item["WorkInstructionID"] = txtID.Text;
                                }

                                item["Revision"] = txtRevision.Text;
                                item["Description"] = txtDescription.Text;
                                item["WorkRecordID"] = new SPFieldLookupValue(workRecId);
                                item.Update();
                                //newFile.CheckIn("New", SPCheckinType.OverwriteCheckIn);

                                web.AllowUnsafeUpdates = false;
                            }
                            else
                            {
                                web.AllowUnsafeUpdates = true;
                                SPDocumentLibrary documentLib = web.Lists["WorkInstruction"] as SPDocumentLibrary;
                                SPListItem item = documentLib.GetItemById(strCheckListID);
                                if (isCheckListIdExists)
                                {
                                    item["WorkInstructionID"] = item["WorkInstructionID"].ToString();
                                }
                                else
                                {
                                    item["WorkInstructionID"] = txtID.Text;
                                }
                                item["Revision"] = txtRevision.Text;
                                item["Description"] = txtDescription.Text;
                                item["WorkRecordID"] = new SPFieldLookupValue(workRecId);
                                item.Update();
                                web.AllowUnsafeUpdates = false;
                            }

                        });
                    }

                }
            }
            catch (Exception ex)
            {
                txtDescription.Text = ex.StackTrace.ToString();
            }
            txtID.Text = "";
            txtRevision.Text = "";
            txtDescription.Text = "";
        }

    }
2
  • 2
    More information needed. Can you post the code? Are there any hard coded references e.g. guid in the code?
    – Underverse
    Commented Jul 21, 2015 at 7:46
  • 1
    Yes, a lot more details are required: code (as suggested by Underverse), but also purpose of the Web part, Tools and API used to build it, deployment mecanisms, SP versions, and most importantly the meaning of "it is not working" (like error messages...).
    – Evariste
    Commented Jul 21, 2015 at 8:42

1 Answer 1

0

Not sure what is the problem but if you rewrite your try and catch to use correctly the SPWeb and SPSite objects you might get some helpful error. In your example you are disposing objects before catch.

String str;
SPSite oSPSite = null;
SPWeb oSPWeb = null;

try
{
   oSPSite = new SPSite("http://server");
   oSPWeb = oSPSite.OpenWeb(..);

   str = oSPWeb.Title;
}
catch(Exception e)
{
   //Handle exception, log exception, etc.
}
finally
{
   if (oSPWeb != null)
     oSPWeb.Dispose();

   if (oSPSite != null)
      oSPSite.Dispose();
} 

https://msdn.microsoft.com/en-us/library/aa973248(v=office.12).aspx

Hope that will help to nail the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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